How to tweet from GAE - python

I want to be able to Tweet from my app running on GAE.
Please suggest some Python library or HTTP API for the purpose.

About python-twitter: I think you can use this lib it seems to be compatible with GAE: http://code.google.com/p/python-twitter/source/browse/twitter.py
Also:
Twitter has a very great REST API https://dev.twitter.com/docs/api, You can also to simply use urlfetch and simplejson from appengine.
For authentication Twitter uses OAuth and recommend to understand how it work:
Twitter supports a few authentication methods and with a range of
OAuth authentication styles you may be wondering which method you
should be using. When choosing which authentication method to use you
should understand the way that method will affect your users
experience and the way you write your application.
Twitter share a very great how to https://dev.twitter.com/docs/auth/oauth
You can also see the part of code: http://code.google.com/p/jaikuengine/source/browse/trunk/oauth_client.py from jaikuengine.

This project worked for me: https://github.com/tav/tweetapp/blob/master/standalone/twitter_oauth_handler.py
It's only one file so it's easy to get it started and uses OAuth for authentication with twitter.

I have used twython in the past. I can't remember what made me select it over other libraries but I was using it on GAE and it is kept up-to-date.

You might find the Tweet Engine project of interest. It demonstrates quite simply how to use the Twitter REST API from App Engine.

Related

Stuck with oauth when trying audiomack api

All I know about API authentication is just password and bearer token. (and NO AUTH too ;)) And I got this OAuth problem when I was trying to use audiomack API.
https://www.audiomack.com/data-api/docs
This is their API documentation. They say
Rather than manually creating code for OAuth, we recommend instead using one of the pre-built libraries available for your programming language.
And I got piles of python libraries here: https://oauth.net/1/#:~:text=Max%20Countryman%20maintains,Tornado%20Auth%20package
Because I am new to OAuth, and also do not know how to get this consumer key and secret from my audiomack account (newly created for test use), these repos give no meaning to me.
Is there anyone who can help me out? I want to know how to make a proper OAuth step to use this API.
A step-by-step guidance or relevant link will be appreciated. Thanks in advance.

Flask-Dance for OAuth

I am relatively new to programming, and have been learning about OAuth2 with Python. Specifically, I have been learning how to use Flask-Dance, beginning with its implementation for Google authentication. I am wondering:
1) Which Google API does Flask-Dance make use of? I see that the default scope in F-D is 'profile', but I can't seem to figure out what other scopes are available
2) What is the difference between the Google API Explorer and the Google OAuth2 Playground? When/why would I use one over the other?
Any help would be appreciated.
Thanks!
1.) Flask dance makes use of OAuth. Oauth is used specifically for allowing users to give authorization to your app or for authenticating users with the OpenID standard. What this means is, say, you want to get data from a user's google account, e.g. you want a list of their google contacts, you'll use OAuth to get authorization from that user. Another use case is if you want to let users login to your application using google. You'd use Oauth for that. In this case you'll be dealing mostly with access tokens and authorization codes, this is what Flask Dance is for.
For more information on OAuth, here's a video that explains it and its various use cases in plain English: https://www.youtube.com/watch?v=0VWkQMr7r_c
2.) The Google API is for a completely different use case. You're not trying to get data from a user's google account and you're not trying to let users login to your application with google. You want to simply use a Google service on your application. For instance you want to use Google Maps in your app so that you can let users of your app get directions to a place. In this case, you'll be working with API keys that identify your application.

use python / django to let users login to my site using their google credentials

I want to let users use their google account to login to my website. Exactly the way SO lets me. Can anyone please point in the right direction? I'm assuming the oAuth library is to be used but what I'd really like is a snippet of code I can directly copy paste and get this to work.
It's not OAuth particularly that you need (OAuth is for authorising access for one website to specific private content held on another), but OpenID - which is meant for authentication rather than authorisation. (Some sites, like Twitter, do provide authentication services via OAuth, but that's not what it's primarily for.) I have used python-openid which is fairly straightforward to use, or you can look at django-openid - though it admits to being incomplete, you could get some idea of how to implement OpenID support.
The problem's a little too involved to admit a copy-and-paste solution, but it's not especially hard to do this.
Update: piquadrat's link (in he comment) is definitely worth following.
You may want to check out django-piston which is a mini-framework with oAuth built in. Here's a tutorial on how to set it up.
You might consider using Django-Socialauth, as it supports
Twitter
Gmail
Facebook
Yahoo (essentially openid)
OpenId

Noob Question: Python + Twitter + App Engine - Oauth

I'm sorry but I'm having some trouble implementing Oauth within my app engine python project.
I've been working from http://github.com/tav/tweetapp, but I don't think I have a strong enough grasp on this platform to understand how to implement this class within my main.py I'm building the rest of my app in.
This maybe a feeble attempt, but here is what I have so far:
twa = twitter_auth
client = twa.OAuthClient('twitter')
I've created a source folder within my project called "twitter_auth" and that contains a file within it called "twitter_auth.py" which contains the above linked library, and a file called __ init__.py (no space) which is completely empty.
I really have no idea what to do from here :/
Let me recommend taking a look at the tweepy library and some example tweepy apps. Specifically here: http://github.com/wasauce/tweepy-examples
This shows how to use oauth to authenticate a user: http://github.com/wasauce/tweepy-examples/tree/master/appengine/oauth_example/
As Hagge said, it sounds like your issue is more with the tweetapp library than with App Engine. However, if you would like to know more about OAuth on App Engine and if I may be allowed to link to myself, my two articles on the topic seem to be reasonably popular.
The tweetapp library was a an early prototype for Twitter OAuth on twitter. Tav did the heavy lifting and I deployed the site http://twitteroauth.appspot.com , using some of the tweetapp library. The actual source of that site is here (I need to update the site to point here): http://github.com/ryanwi/twitteroauth
I am still using it in production, but, it has aged and does not work for all API calls. I'd recommend trying a different, more up to date and maintained library as others have mentioned.
But, take a look at the twitteroauth source if you want to try to get a first attempt working.
These two are on Twitter's list
http://github.com/brosner/python-oauth2
http://code.google.com/p/oauth-python-twitter2/
I'm not familiar with that library, but after a quick look and seeing the warning that it is not maintained I'd search for something better. I implemented a simple Twitter connection based on Tornado's auth: see an example of how to make Twitter API calls here (and an authentication example here). In case you don't want to use tipfy, I recommend implementing the python-twitter library in your framework of choice.

Is it possible to update a Google calendar from App Engine without logging in as the owner?

I'd like to be able to use the Google Data API from an AppEngine application to update a calendar while not logged in as the calendar's owner or the a user that the calendar is shared with. This is in contrast to the examples here:
http://code.google.com/appengine/articles/more_google_data.html
The login and password for the calendar's owner could be embedded in the application. Is there any way to accomplish the necessary authentication?
It should be possible using OAuth, i havent used it myself but my understanding is the user logs in and then gives your app permission to access their private data (e.g. Calendar records). Once they have authorised your app you will be able to access their data without them logging in.
Here is an article explaining oauth and the google data api.
http://code.google.com/apis/gdata/articles/oauth.html
It's possible to use ClientLogin as described here:
http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Response
Note the section at the bottom of the document that mentions handling a CAPTCHA challenge.
There's example code included in the gdata python client in
samples/calendar/calendarExample.py
You need to call run_on_app_engine with the right arguments to make this work as described in the Appendix here:
http://code.google.com/appengine/articles/gdata.html
Note that the same document recommends against using ClientLogin for web apps. Using OAuth or AuthSub is the correct solution, but this is simpler and good enough for testing.

Categories