Is there a Twitter API version 1.1 call that would provide the total number of friends a user is following?
The GET Friends/ids is the closest I found, however, it provides a list of all a user friend ids, not a total amount.
https://api.twitter.com/1.1/friends/ids.json?cursor=-1&screen_name=twitterapi&count=5000
Yes. If you use the users/show endpoint of the v1.1 API you can retrieve information about a particular user.
One of the fields that is returned is called friends_count - this is the value you are looking for.
Full details here: https://dev.twitter.com/docs/api/1.1/get/users/show
The answer above is the right answer and if you want to try a better way you can use as follows:
this is twarc library for python that is helpful for hydrating ids from tweeter API.
twarc is a command line tool and Python library for archiving Twitter JSON data. Each tweet is represented as a JSON object that is exactly what was returned from the Twitter API.
for using this library in python you can simply write the code below in a python file.
from twarc import Twarc
t = Twarc(consumer_key, consumer_secret, access_token,access_token_secret)
for tweet in t.hydrate(open('ids.txt')):
print(tweet["text"])
the consumer_key, consumer_secret, access_token, access_token_secret comes from (https://developer.twitter.com/apps) in your tweeter developer account.
This is for bulk user-ids that saved in ids.txt file that separated by enter ("\n")
Related
I'm experimenting with twitter REST API with Ruby on Rails.
I'm using twitter gem for the same. I could get the client object using in my code.
client = current_domain.twitter_accounts.first.client
following the documentation given here
The client object works fine. But I couldn't get DirectMessages in the same way.
Also followed this documentation. Here I could not find a way to get DirectMessages. Is there a way in REST API to get twitter direct messages. Or do I need to implement Streaming API.
http://www.rubydoc.info/gems/twitter/Twitter/REST/Client
Methods included from DirectMessages
#create_direct_message, #destroy_direct_message, #direct_message, #direct_messages, #direct_messages_received, #direct_messages_sent
These map to the REST API endpoints
https://dev.twitter.com/rest/reference/get/direct_messages
https://dev.twitter.com/rest/reference/get/direct_messages/sent
n.b. you won't get group messages through this API and will need to rebuild an inbox model e.g. sequence replies of replies between yourself and the recipient.
I have read the documentation of twitter , and created an app and have all the keys needed .
Now i am trying to understand that simple one line http request ,to get a user latest twits .
I have read this Simplest PHP example for retrieving user_timeline with Twitter API version 1.1
but there is not one line code in there to make the request ( i don't know java script).
so , i have this :
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2
Which will not work because my keys should be in this line, but i don't understand how to add them?? where and how i add my keys to this ?
This url is like a node or address so twitter server knows what kind of request you need.
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2
Beside url you can pass many other parameter using http header, which is best to be used with server langunge programming, e.g PHP.
In PHP you can pass your credentials by changing header. While current twitter API are using Oauth, it's going to difficult to learn using Oauth this way, the easiest option is to use others' library. Check out 'twitter API library' (just google it)
I found that we can use stream API to get the latest tweets based on hash tags or keywords.
It says you have to keep your http connection open. I am having a doubt regarding this.
Can anyone give me an example of stream API in php?
And other thing can I skip hashtag and keyword parameter is this API ? So I can all the statuses?
Can I pass a parameter like latitude and longitude to get tweets from the specific region?
You can request tweets by location, see their API documentation for specifying location boundaries:
https://dev.twitter.com/docs/streaming-apis/parameters#locations
I'm not really sure where to begin with this.
Prior to the upgrade to version 1.1 of the API I was able to request tweets in XML format using
$url = 'http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=' . $TWITTER_USERNAME;
A couple of things have changed, the return format is now JSON which isn't a problem but I'm not sure how to authenticate my app to request the tweets in JSON format.
I've read this link but am unsure how I'm supposed to implement it.
For instance, where do I get the consumer secret from ?
How do I request a bearer token in PHP ?
Any pointers would be great
you need to use plugin that is written for v1.1, In new version they have added security layer so you need to be authorized in order to get the tweets via API, here are the links that will be helpful for you
http://www.webdevdoor.com/php/authenticating-twitter-feed-timeline-oauth/ http://www.fullondesign.co.uk/coding/2516-how-use-twitter-oauth-1-1-javascriptjquery.htm
I wish to get tweets with a keyword. But There is no result with any keyword.
http://search.twitter.com/search.json?q=summer
How to get results with Twitter Search API?
Version 1 of the twitter API has been deprecated and is being removed. Not sure how you can miss the giant warnings on the twitter dev site ;) This means simple code like the above will not work any more.
So, you now need to make authenticated requests (OAuth) using the 1.1 API, and it's nowhere near as simple as just doing a (in PHP) file_get_contents(http://search.twitter.com/ ...).
I couldn't see any server-side languages you use from your profile, but I wrote a lengthy post explaining the issue (with pictures) and how to use a php library to perform authenticated requests.