I am trying to write a web application with Python using the Fitbit API. I need to authenticate the user with OAuth 2.0 in the browser. Right now I'm trying to use python-fitbit, though I'm not sure there's a better way to do this. Here is my code:
import fitbit
client = fitbit.FitbitOauth2Client('client_id', 'client_secret')
res = client.make_request("https://api.fitbit.com/1/user/-/activities.json", None, method='GET')
When I run it, I get ValueError: Missing access token. What am I doing wrong here? I feel totally in over my head with this.
Did you notice this known bug in python-fitbit?
https://github.com/orcasgit/python-fitbit/issues/70
Seems like it might be what you're hitting. That user described a workaround in using another fitbit python client.
Edit:
Adding quote from other article for a better answer!
As I successfully obtain my token using another Fitbit API client (https://github.com/magnific0/FitBit.py), it seems there is a problem
with your script "gather_keys_oauth2.py".
I would say that oauthlib call using OAuth2Session should not try to
validate the token during the request phase.
Looks like the issue was fixed in the code (gather_keys_oauth2.py) a week or so ago, but I couldn't find the documentation how to use the fixed code.
Looking for simple example if possible.
#orcasgit/orcas-developers Please review. This should get the OAuth2 authentication working again. Works in my testing.
Related
I'm trying to connect my zendeskAPI to create a ticket with a python application but I surely missed something because I just got the "Couldn't authenticate you" error, I've created and activate the api token in Zendesk and I tried in Postman But i came to the same error.
Here its my url and the headers (the variables are correctly connected)
And the token authorization added too
I already saw some topics with the same problem but no solutions worked. Do you have an idea ?
I tried to use Webhooks on Zendesk but the company i work for doesn't have the extension. Is it possible to install it ?
For postman authorization, you need to set the type to Basic Auth rather than API Key. It will encode your username {{mail}}/token and API token for you. You will NOT need to manually add an authorization header and encode the credentials separately.
Also if you are using python, consider using a community developed client that would make your API calls much easier. Zenpy is still maintained.
Totally lost here. I have a weather station that I developed on Python for a Raspberry PI. Very nice and useful (I am a biker). But it recently stopped working!
I was using weather.com and Yahoo APIs. weather.com is not free since 01/15/2020, and Yahoo now requests an Oauth access that I don't have. I have signed up and I have my AppID, ClientID and SecretCode... But I don't have a clue about what to do with it. After reading a lot, I think that I have to get a Token, but I don't know how to get it and what to do with it (store it on disk???). In addition to that, it seems that it needs to be refreshed from time to time.
Everything I found is on C++, java or php (that I don't understand); and it is very distinct from one source to another, so I am not sure which one to use.
If someone could help me to understand what to do, where to look or an example, I would really appreciate that.
To the moment, I tried this which "promisses" to manage oauth connections, with no success:
from yahoo_oauth import OAuth1
oauth = OAuth1(None, None, from_file='oauth1.json')
if not oauth.token_is_valid():
oauth.refresh_access_token()
# Example
response = oauth.session.post(url, data=body)
Nevertheless, I think that this is just to refresh the token, but as I said before, I don't know how to get it and what to do whit it.
All you actually need is here, with python example :)
Documentation yahoo.
Here are the stepss for setup: Setup steps
What is going on with the token? Yahoo needs some verification that it is you who make request - so you need to add the Authorization token to you request. That's all :)
Ask here, if you had more questions :)
Some time ago I wrote a little tool for a friend of mine. I retrieved all stream-links (like this) from a soundlist and downloaded all those with a small python script.
Since begin of March, soundcloud must have changed something, and now my cronjob recieves 401 Unauthorized errors. I've read through the soundcloud API, but that whole Access Token does not really fit my needs.
Has anyone of you an idea of easily dealing with this problem? Thanks.
As Makoto said, 401 seems like you have lost priviledges to access through your OAuth token so I would double check to make sure your app is still available and that your tokens are correct. You can check on the Your Apps Page.
Also, I noticed that your url seemed a bit different than what the SC api shows. Once you resolve to get a proper track id, the convention for a stream url is:
http://api.soundcloud.com/tracks/{id}/stream
This can be found in their track documentation.
Read the documentation here. You have to add your client_id parameter to the stream url and then you will be redirected to the stream link (mp3).
I am trying to find the easiest way how to use Facebook Graph API using my favorite Requests library. The problem is, all examples I found are about getting user access token, about redirects and user interaction.
All I need is only application access token. I do not handle any non-public data, so I need no user interaction and as my final app is supposed to be command-line script, no redirects are desired.
I found something similar here, but it seems to be everything but elegant. Moreover, I would prefer something using Requests or Requests-OAuth2. Or maybe there is library for that? I found Requests-Facebook and Facepy (both Requests based), but again, all examples are with redirection, etc. Facepy does not handle authorization at all, it just accepts your token and it is up to you to get it somehow.
Could someone, please, provide a short, sane, working example how to get just the application access token?
Following https://developers.facebook.com/docs/technical-guides/opengraph/publishing-with-app-token/:
import requests
r = requests.get('https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=123&client_secret=XXX')
access_token = r.text.split('=')[1]
print access_token
(using the correct values for client_id and client_secret) gives me something that looks like an access token.
If you just need a quick/small request, you can manually cut and paste the access token from here into you code: https://developers.facebook.com/tools/explorer
Note: Unlike Richard Barnett's answer, you'll need to regenerate the code manually from the graph api explorer every time you use it.
I'm sure there aren't too many people on the site that have experience with this but I'm going to get it a shot. I tried installing Django Social Auth for social authentication on a site I am designing but when ever I try logging in using any of the services I get and error that says
Incorrect authentication service
I am positive that I have the right consumer and secret key inputted and have reinstalled using pip. Should I try with the just code in the project instead of using the pip version.
Here is my settings.py and local_settings.py combined (couldn't get the code to format correctly on here so I used Pastebin)
[http://pastebin.com/7awDzSxX][1]
So far I've tried getting the example implementation to work and have failed at that as well. I've been trying to copy as much as possible for it but nothing really seems to work. If you'd like more info about the situation let me know and I can post more code.
Cheers.
Looks like incorrect url tag parameter. For me works this one
Enter using Twitter
I was trying to authenticate with Twitter and received the same error. The I realized the twitter backend was commented. It should look like this, obviously applied to whatever backend you're using:
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'social_auth.backends.twitter.TwitterBackend',
)