Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DJREMiX6/68635ef2519383e6d7b9793bbb5b11e0 to your computer and use it in GitHub Desktop.
Save DJREMiX6/68635ef2519383e6d7b9793bbb5b11e0 to your computer and use it in GitHub Desktop.
Instagram_Basic_Display_API
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Instagram_Basic_Display_API.iml" filepath="$PROJECT_DIR$/.idea/Instagram_Basic_Display_API.iml" />
</modules>
</component>
</project>
import requests
import json
def makePostApiCall(url, endpointParams, debug='no'):
"""Make a POST API call
url:
Endpoint's URL (string)
endpointParams:
Endpoint's request params (dict)
debug:
Debug param for showing data 'yes/no'(string)"""
data = requests.post(url, endpointParams)
response = dict()
response['url'] = url
response['endpoint_params'] = endpointParams
response['endpoint_params_pretty'] = json.dumps(endpointParams, indent=4)
response['json_data'] = data.content
response['json_data_pretty'] = json.dumps(data.content, indent=4)
def makeGetApiCall(url, endpointParams, debug='no'):
"""Make a GET API call
url:
Endpoint's URL (string)
endpointParams:
Endpoint's request params (dict)
debug:
Debug param for showing data 'yes/no'(string)"""
data = requests.get(url, endpointParams)
response = dict()
response['url'] = url
response['endpoint_params'] = endpointParams
response['endpoint_params_pretty'] = json.dumps(endpointParams, indent=4)
response['json_data'] = data.content
response['json_data_pretty'] = json.dumps(data.content, indent=4)
if debug == 'yes':
displayApiCallData(response)
return json.loads(response.content)
def getCreds():
"""Get Credentials by settings.json file
Return: A dict with settings info"""
f = open('settings.json', 'r')
creds = json.load(f)
f.close()
return creds
def changeCreds(credNames = list(), values = list()):
"""Change credentials values by settings.json file
credName:
Credentials's names
value:
New Credentials's values"""
creds = getCreds()
for n,v in zip(credNames, values):
creds[n] = v
f = open('settings.json', 'w')
f.write(json.dumps(creds, indent=4))
return
def addCreds(credNames = list(), values = list()):
"""Add credentials and values on settings.json file
credName:
Credentials's name
value:
New Credentials's value"""
creds = getCreds()
for n,v in zip(credNames, values):
creds[n] = v
f = open('settings.json', 'w')
f.write(json.dumps(creds, indent=4))
return
def delCreds(credNames = list()):
"""Delete credentials and values on settings.json file
credNames:
Credentials's name"""
creds = getCreds()
for n in credNames:
del(creds[n])
f = open('settings.json', 'w')
f.write(json.dumps(creds, indent=4))
return
def displayApiCallData(response):
print('\nURL: ' + response['url'])
print('Endpoint Params: ')
print(response['endpoint_params_pretty'])
print('Response Data:')
print(response['json_data_pretty'])
def displayCreds():
creds = getCreds()
print('\nSettings:')
for k, i in zip(creds.keys(), creds.values()):
print(k + ': ' + i)
"""
displayCreds()
addCreds(['ciaone'], ['test'])
displayCreds()
changeCreds(['ciaone'], ['ciccino'])
displayCreds()
delCreds(['ciaone'])
displayCreds()
"""
from _defines import makePostApiCall, makeGetApiCall, getCreds
{
"client_id": "2628069500797304",
"client_secret": "9a05f5423d7f7f9e9b536136881069e1",
"redirect_uri": "https://fsfrancescogirelli.altervista.org/",
"endpoint_base": "https://api.instagram.com/"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment