Basically trying to follow another users followers, using the twython library
I am new to twitter, python, and pwython so keep that in mind.
Atm using 'get_friends_ids' and able to retrieve a list of id numbers.
The problem is I dont know how to break this down and follow all of them.
What do I do!?
What I have so far working..
oauth working..
t = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
tysfriends = t.get_friends_ids(screen_name="fucktyler")
print tysfriends
This didnt work: t.create_friendship(user_id = tysfriends)
I want to add the lis tof friends 'tysfriends'
The following code should work
t = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
tysfriends = t.get_friends_ids(screen_name="fucktyler")
for friend_id in tysfriends['ids']:
t.create_friendship(user_id=friend_id)
Thanks for using Twython!
Related
I am trying to parse the twitters on specific topic using Python. However, the code runs flawlessly but I need to add the geolocation as one of the core search criteria in parsing. Any suggestion how to do so?
Could you provide more example code?
If I'm understanding your question correctly, you could use the tweepy library. This could also be achieved using Get requests.
I'll provide a Tweepy example:
# enter twitter info from [Twitter developers site][2]
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_KEY = ''
ACCESS_SECRET = ''
# setup authorization
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
Location based search can be done using geocode in the tweepy.search function:
# skeleton query:
geo_based_tweets = api.search(q='some text I want to search on', geocode='long,lat,radius')
# example query about the vikings in Minneapolis:
api.search(q="vikings OR football", geocode='44.9833,-93.2667,10km', count=100)
Hope that's helpful!
I have a twitter account with an App made, currently it's setup so students can tweet from our website and as such their tweets show "via SchoolAppNameHere" at the bottom of their tweets.
Is it possible to use Twython to use the Appkey and secret key and then get auth tokens from a completely different so when I was to run the bit of code below it would tweet from an account what didn't create the app...
from twython import Twython
APP_KEY = ''
APP_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_status(status="test")
Any ideas would be much appreciated :)
Edit, Updated example/explanation below:
Let's say the following image's are from the account "stackoverflowapp" and the app called "Stackoverflow Test App":
Using the following bit of code would tweet from the account "stackoverflowapp" with the tweet "test" via the applicationg called "Stackoverflow Test App"
from twython import Twython
APP_KEY = 'coN_kEY_123456789'
APP_SECRET = 'cOn_sEcr3t_123456789'
OAUTH_TOKEN = 'Acc3ss_tok3N_123456789'
OAUTH_TOKEN_SECRET = 'aCCeSS_tOkEn_sEcrET_123456789'
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_status(status="test")
Let's say that the following image is from the account "useraccount1" and the app is called "testing123":
So now that I have the access tokens to login to the account "useraccount1", how can I tweet via the app called "Stackoverflow test app" which was created by the user: "stackoverflowapp" example of what I tried is below:
from twython import Twython
APP_KEY = 'coN_kEY_123456789'
APP_SECRET = 'cOn_sEcr3t_123456789'
OAUTH_TOKEN = 'Acc3ss_123456789'
OAUTH_TOKEN_SECRET = 'aCCeSS_sEcrET_123456789'
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_status(status="test update")
Unfortunately, I get the error:
TwythonAuthError: Twitter API returned a 401 (Unauthorized), Could not authenticate you
This is of course, possible. When you create an application in Twitter, they give you your own authentication tokens for you to use immediately, as a convenience.
Use the access token string as your "oauth_token" and the access token secret as your "oauth_token_secret" to sign requests with your own Twitter account. Do not share your oauth_token_secret with anyone.
To get keys for other accounts for the same application, you need to request more keys for each account. This is described in detail here: https://dev.twitter.com/docs/auth/obtaining-access-tokens
Since it sounds like you're going to be doing the authorization yourself, the simpler PIN-based approach should probably be used.
You're using twython, obtaining these can be done using the library: https://twython.readthedocs.org/en/latest/usage/starting_out.html#authentication
get_authentication_tokens and get_authorized_tokens are the methods you're looking for.
from twython import Twython
import sys
APP_KEY = 'coN_kEY_123456789'
APP_SECRET = 'cOn_sEcr3t_123456789'
twitter = Twython( APP_KEY, APP_SECRET )
auth = twitter.get_authentication_tokens()
print( 'Visit %s and enter your PIN: ' % auth.get( 'auth_url' ) ),
pin = sys.stdin.readline().strip()
twitter = Twython( APP_KEY, APP_SECRET, auth.get( 'oauth_token' ), auth.get( 'oauth_token_secret' ) )
tokens = twitter.get_authorized_tokens( pin )
print( 'OAUTH_TOKEN: %s' % tokens.get( 'oauth_token' ) )
print( 'OAUTH_TOKEN_SECRET: %s' % tokens.get( 'oauth_token_secret' ) )
Store OAUTH_TOKEN and OAUTH_TOKEN_SECRET some place safe and reuse at will. Also, make sure you authorize the correct account when visiting the URL and getting the PIN.
All your API calls will be made on bahalf the account that authorized access via the tokens and your via line will be your original application. Use the appropriate tokens for each account you'd like to tweet from, it's not possible to mix and match.
I'm facing an issue using Koala 1.7.0rc1 and the new Facebook graph api. I'm trying to retrieve number of likes for a post using this request [object_id]/likes?summary=1. This query works in Facebook Graph Explorer but I cannot access 'summary' using Koala :
likes = graph.get_object("5718732097_10151698726822098", summary: 1){|data| data['likes']}
# OR
likes = graph.get_object("5718732097_10151698726822098/likes?summary=1")
You should do:
graph.get_object(your_post_id, :fields => "likes.summary(true)")
The api documentation that Facebook gave is kind of misleading here:
https://developers.facebook.com/docs/reference/api/post/
It says summary = 1 which should be summary = true in rails
You'll need to get the summary data from the raw response in Koala, like so:
likes = graph.get_object("5718732097_10151698726822098/likes?summary=1").
raw_response["summary"]["total_count"]
I am trying to use koala gem to retrieve the real like numbers of a Facebook post.
In the Facebook graph explore, I have tried:
5718732097_10151698726822098/likes?summary=1
according to the https://developers.facebook.com/docs/reference/api/post/ page.
This query works and return a hash with a entry:
"summary": {
"total_count": 19541
}
So, how could I do this query using koala gem. The main problem is that I do not know how to pass the summary = 1 to the get_object function.
I have tried:
1.likes = graph.get_object("5718732097_10151698726822098", summary: 1){|data| data['likes']}
2.likes = graph.get_object("5718732097_10151698726822098/likes?summary=1")
neither of them works, any one can help? Thanks a lot!
Can any one help me about this?
I just got this answer by myself:
So I should do
graph.get_object(your_post_id, fields => "likes.summary(true)")
The api documentation that Facebook gave is kind of confused me here: https://developers.facebook.com/docs/reference/api/post/
It says summary = 1 which should be summary = true in rails
when a user login using facebook then i need collect all the movies list liked by the user and his/her friends.
user = FbGraph::User.fetch('me', :access_token => "access_token")
userFrnd = user.friends
movies=[]
userFrnd.each do | uf |
frnd = FbGraph::User.fetch(uf.raw_attributes['id'], :access_token => "access_token")
movies << frnd.movies
end
final_movie_list = movies.flatten.uniq_by {|track| track.raw_attributes["id"]}
this is my fb_graph function and it's working fine.but i need to make it as batch request since the i have 360 friend it take 360 request to process the above function correctly.but help me out to optimize this and reduce the time it takes to calculate this function.
I came to know that batch request may help me but,i don't know how to do that in fb_graph.
Please help me
I'm using FbGraph from ( github.com/nov/fb_graph ) Version: 2.7.8 and I'm able to make a batch request for 100 users, at a time and get following information about them by default.
I'm not using any access token. So you might be able to get more information including movies.
id
name
first_name
last_name
link
username
gender
locale
Here's the demonstration code where ids is an array of Facebook User Ids:
r = FbGraph::User.fetch("?ids=#{ids.join(",")}")
r.raw_attributes #information about the users hashed by their id (String)