I'm trying to familiarize with the library python-instagram.
I've done this code:
from instagram.client import InstagramAPI
clientid = '***'
clientsecret = '***'
api = InstagramAPI(client_id=clientid, client_secret=clientsecret)
tag_name = raw_input("Write the word that you want")
filtered_media = api.tag_recent_media(count=20, max_id=1, tag_name=tag_name)
for media in filtered_media:
print media.images['standard_resolution'].url
and I get the following error using the command line (I have a mac):
Traceback (most recent call last):
File "test.py", line 7, in <module>
filtered_media = api.tag_recent_media(count=20, max_id=1, tag_name=tag_name)
File "build/bdist.macosx-10.6-intel/egg/instagram/bind.py", line 197, in _call
File "build/bdist.macosx-10.6-intel/egg/instagram/bind.py", line 189, in execute
File "build/bdist.macosx-10.6-intel/egg/instagram/bind.py", line 163, in _do_api_request
instagram.bind.InstagramAPIError: (400) OAuthAccessTokenException-The access_token provided is invalid.
Someone knows what is happen? THANKS
I would suggest you to take a look at this sample app . You will get to know how to use python-instagram library.
In your code , You are passing client Id in InstagramAPI(). But as per their sample app required argument is access_token.
code snippet from sample_app.py
api = client.InstagramAPI(access_token=access_token, client_secret=CONFIG['client_secret'])
tag_search, next_tag = api.tag_search(q="backclimateaction")
tag_recent_media, next = api.tag_recent_media(tag_name=tag_search[0].name)
To get tag_search result you must have access_token. you can read this documentation to learn how to generate access token from your app.
Related
after reading the offical google translate api document, it provide us with the following sample code:
from google.cloud import translate
def translate_text(text="Hello, world!", project_id="weighty-site-333613"):
client = translate.TranslationServiceClient().from_service_account_json('key.json')
location = "global"
parent = f"projects/{project_id}/locations/{location}"
response = client.translate_text(
request={
"parent": parent,
"contents": [text],
"mime_type": "text/plain",
"source_language_code": "en-US",
"target_language_code": "zh-CN",
}
)
for translation in response.translations:
print("Translated text: {}".format(translation.translated_text))
translate_text()
These code worked properly on google cloud terminal.
However, even if i put the "key.json" file in the same folder, an error like this is shown:
/usr/local/bin/python3.6 /Users/jiajunmao/Documents/GitHub/translator_of_excel/google_trans.py
Traceback (most recent call last):
File "/Users/jiajunmao/Documents/GitHub/translator_of_excel/google_trans.py", line 37, in <module>
translate_text()
File "/Users/jiajunmao/Documents/GitHub/translator_of_excel/google_trans.py", line 22, in translate_text
client = translate.TranslationServiceClient().from_service_account_json('key.json')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/cloud/translate_v3/services/translation_service/client.py", line 354, in __init__
always_use_jwt_access=True,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/cloud/translate_v3/services/translation_service/transports/grpc.py", line 158, in __init__
always_use_jwt_access=always_use_jwt_access,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/cloud/translate_v3/services/translation_service/transports/base.py", line 110, in __init__
**scopes_kwargs, quota_project_id=quota_project_id
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/auth/_default.py", line 488, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
Process finished with exit code 1
can someone tell me what should i do at this step? thank you so much
You need service account json file with correct permissions from GCP under IAM & Service Accounts.
Then you need to implement command,
GOOGLE_APPLICATION_CREDENTIALS = "/path/to/your/service_account.json"
Generating an access token for the Python Instagram API requires running this file and then entering a Client ID, Client Secret, Redirect URI, and Scope. The console then outputs a URL to follow to authorize the app and asks for the code generated afterwards. Theoretically after this process it should return an access token.
Instead, it's throwing an error:
Traceback (most recent call last):
File "get_access_token.py", line 40, in <module>
access_token = api.exchange_code_for_access_token(code)
File "C:\Users\Daniel Leybzon\Anaconda2\lib\site-packages\instagram\oauth2.py", line 48, in exchange_code_for_access_token
return req.exchange_for_access_token(code=code)
File "C:\Users\Daniel Leybzon\Anaconda2\lib\site-packages\instagram\oauth2.py", line 115, in exchange_for_access_token
raise OAuth2AuthExchangeError(parsed_content.get("error_message", ""))
instagram.oauth2.OAuth2AuthExchangeError: You must provide a client_id
Screenshot provided for context:
I'm trying to get my account information by evernote api on python, however, I got errors :
Traceback (most recent call last): File "", line 1, in
File "build/bdist.linux-x86_64/egg/evernote/api/client.py", line 148, in delegate_method
File "build/bdist.linux-x86_64/egg/evernote/edam/userstore/UserStore.py", line 1033, in getUser
File "build/bdist.linux-x86_64/egg/evernote/edam/userstore/UserStore.py", line 1058, in recv_getUser
evernote.edam.error.ttypes.EDAMSystemException: EDAMSystemException(errorCode=8, rateLimitDuration=None, _message='authenticationToken')
My python code as below:
from evernote.api.client import EvernoteClient
dev_token="my develop token"
client = EvernoteClient(token=dev_token)
userStore = client.get_user_store()
user = userStore.getUser()
I'm sure I've generated a valid developer token for my Evernote account, as shown in the picture, I have a develop token in my account link
Is there anything I missed?
By the way, I use the code above and replace the key with another develop token generated by Evernote sandbox account, it's ok.
If you are not on sandbox, try:
client = EvernoteClient(token=dev_token, sandbox=False)
I am trying to use twython to make API call for twitter and get the tweets. And I am receiving 403 error from twitter that says SSL is required. Can anyone help me how to finish this simply query?
Btw, I am using python 2.7. The OS is Windows 7.
from twython import Twython
tw = Twythonfrom twython import Twython(app_key=app_key, app_secret=app_secret, oauth_token=oauth_token, oauth_token_secret=oauth_token_secret)
search = tw.search(q = 'Sandra')
for result in search:
print result
And the error message
traceback (most recent call last):
File "C:\Users\local.admin\My Documents\LiClipse Workspace\test\TwythonTest.py", line 33, in <module>
search = tw.search(q = 'Sandra')
File "C:\Python27\lib\site-packages\twython\twython.py", line 133, in <lambda>
return lambda **kwargs: self._constructFunc(key, **kwargs)
File "C:\Python27\lib\site-packages\twython\twython.py", line 149, in _constructFunc
content = self._request(url, method=fn['method'], params=kwargs)
File "C:\Python27\lib\site-packages\twython\twython.py", line 218, in _request
retry_after=response.headers.get('retry-after'))
twython.twython.TwythonError: Twitter API returned a 403 (Forbidden), SSL is required
I'm trying to update a document on Google Docs/Drive after I created it, using the GData helpers for Python.
The new version of the API lacks documentation for Py.
client = gdata.docs.client.DocsClient(source=PluginConfig.APP_NAME)
client.http_client.debug = PluginConfig.DEBUG
client.client_login(
PluginConfig.EMAIL,
PluginConfig.PASSWORD,
source=PluginConfig.APP_NAME,
service=client.auth_service
)
[...]
# Upload the text file
ms = gdata.data.MediaSource()
ms.SetFileHandle(file_path, content_type)
doc = gdata.docs.data.Resource(type='document', title=title)
doc.description = gdata.docs.data.Description(description)
doc = client.CreateResource(doc, media=ms)
doc = client.UpdateResource(doc, media=ms, new_revision=True)
Login and document creation work fine, but the Update() receives 400 Bad Request
Traceback (most recent call last):
File "coll.py", line 301, in <module>
main()
File "coll.py", line 293, in main
doc = client.UpdateResource(doc, media=ms, new_revision=True)
File "/usr/lib/python2.7/dist-packages/gdata/docs/client.py", line 344, in update_resource
uri_params=uri_params, **kwargs)
File "/usr/lib/python2.7/dist-packages/gdata/client.py", line 1151, in update_file
auth_token=auth_token, method='PUT')
File "/usr/lib/python2.7/dist-packages/gdata/client.py", line 1085, in upload_file
start_byte, self.file_handle.read(self.chunk_size))
File "/usr/lib/python2.7/dist-packages/gdata/client.py", line 1044, in upload_chunk
raise error
gdata.client.RequestError: Server responded with: 400, Invalid Request
More output: http://pastebin.com/LZL3qV0N
Any help is appreciated.
Try using the newer Drive API, its documentation includes Python samples in the reference guide, a Python quickstart and a complete sample application written in Python on App Engine.