Website google oauth needed - python

Probably this was already answered somewhere, but my google-fu can't get proper keywords for this.
Ok so, I need to get a file from my site which is like foo.bar/foobar/file.ext . That file is always accessible but if you aren't google-authenticated on the site you get a blank file.
How can I get proper authentication with python?
Sorry if this isn't very clear but it's my first time here... Thanks in advance for help

First install the Python SDK here.
Then I would start reading about OAuth here.
They have different examples depending on your use case. (e.g. If you are authenticating a user from their browser, versus from server to server)

Related

Access Yahoo weather using Oauth

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 :)

How can I access SoundCloud-Stream URLs in Python?

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).

How to implement sessions or cookies in Python

can anyone help me get sessions or cookies working with my code here:
http://pastebin.com/2Y2tydsF
I have tried a few session modules that I found with Google but nothing seems to work, or I dont know how to use it.
I have also fiddled with cookies but with no luck
Also, what are the differences, and what are CGI and WSGI apps? and would my code be one of the two?
Thanks
Use gai-sessions. The source includes demos which show how to use it, including how to integrate with the Users API or RPX/JanRain.

How to get access to Gmail in Django

I'm trying to have a page in my webapp with a button 'Connect to Gmail', which sends the user to an authentication page, and when they get back their access token gets saved in my database for later use. I've been literally trying this for weeks, but I can't figure it out. I've tried xoauth, but it seems to only work as a stand-alone script.
Does anyone have some pointers on how to do this?
What you are looking for is OpenID. Check if some fits your need here:
http://djangopackages.com/grids/g/facebook-authentication/ (I know they write facebook authentication, though this page includes openid solutions and full featured solutions with Facebook/Twitter login as well)
I made good experience with django-socialregistration.

Retrieving my own data via FaceBook API

I am building a website for a comedy group which uses Facebook as one of their marketing platforms; one of the requirements for the new site is to display all of their Facebook events on a calendar.
Currently, I am just trying to put together a Python script which can pull some data from my own Facebook account, like a list of all my friends. I presume once I can accomplish this I can move to pulling more complicated data out of my clients account (since they have given me access to their account).
I have looked at many of the posts here, and also went through the Facebook API documentation, including Facebook Connect, but am really beating my head against the wall. Everything I have read seems like overkill, as it involves setting up a good deal of infrastructure to allow my app to set up connections to any arbitrary user's account (who authorizes me). Shouldn't it be much simpler, given I only ever need to access 1 account?
I cannot find a way to retrieve data without having to display the Facebook login window. I have a script which will retrieve all my friends, but it includes a redirect where I have to physically log myself in to Facebook.
Would appreciate any advice or links, I just feel like I must be missing something simple.
Thank you!
Just posting up my notes on the successful advice, should others find this post;
Per Daniel and William's advice, I obtained the right permissions using the Connect options. From William, this link explains how the Facebook connection works
https://developers.facebook.com/docs/authentication/
This section on setting up the actual authentication was most helpful to me.
http://developers.facebook.com/docs/api
Basically, it goes as follows:
Post a link to the following URL. A user will need to physically click on it (even if that user is just you, the site admin).
https://graph.facebook.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=http://www.example.com/HANDLER
This will redirect to a Facebook login, which will return to http://www.example.com/HANDLER after the user authenticates. If you wish to do more than basic reads and news feed updates you will need to include this variable in the above link: scope=offline_access,user_photos. The scope variable just includes a comma separated list of values, which Facebook will explicitly tell the authenticating user about during the login process, and they will have to OK. Most helpful for me was the offline_access flag (user_photos lets you get at their photos too), so I can pull content without someone logging in regularly (so long as I store the access token obtained later)
Have a script located at http://www.example.com/HANDLER that will take a variable from the request (so facebook will redirect to http://www.example.com/HANDLER&code=YOUR_CODE after authentication). Your handler needs to pull out the code variable, and then send the following request:
https://graph.facebook.com/oauth/access_token?
client_id=YOUR_CLIENT_ID&
redirect_uri=http://www.example.com/oauth_redirect&
client_secret=YOUR_SECRET_KEY&
code=YOUR_CODE
This request will return a string of the form access_token=YOUR_ACCESS_TOKEN.
Just parse off the 'access_token=', and you will have a token that you can use to access the facebook graph API, in requests like
http://graph.facebook.com/me/friends?access_token=YOUR_ACCESS_TOKEN
This will return a JSON object containing all of your friends
Hope this saves someone else some not fun time straining through documentation. Thanks for the help!
It is true, that Facebook's API is targeted at developers who are creating apps that will be used by many users.
Thankfully, the new Graph API is much simpler to use than its predecessor, and shouldn't be terribly difficult for you to work with without using or creating a lot of underlying infrastructure.
You will need to implement authorization, but this is not difficult, and as long as you prompt the user for the offline_access permission, it'll only need to be done once.
The documentation on Desktop Authentication would probably be most relevant to you at this point, though you might want to move to the javascript-based authentication once you've got a web app up and running.
Once the authentication is done, all you're doing is making GET requests to various urls and working with the resulting JSON.
Here's the documentation about Events, and you can get a list of friends from the friends connection of a User.
I'm not expert on Facebook/Facebook Connect, however I've seen it used/used applications with it and it seems there's really only the 'official' way to do it. I'm afraid it looks like your best bet would probably be something along the lines of this.
http://wiki.developers.facebook.com/index.php/Connect/Authentication_and_Authorization
Regardless of how you actually 'use' it, you'll still need to authorize the application to connect to the account and this means having a Facebook App as well.
The answer to Facebook application authentication is hard to find but is actually found within the "Analytics" page of the Graph API.
Specify the following: https://graph.facebook.com/oauth/access_token?client_cred&client_id=yourappid&client_secret=yourappsecret , you will then be given an access_token that you may use on all other calls.
The Facebook provided APIs do NOT currently provide this level of functionality.

Categories

Resources