Monitor retweets with PHP - php

I have a website Foo.com that creates a tweet for the user #FooWebsite.
Users on the website can retweet it and users directly on Twitter too.
I would like to monitor in real-time (< 10min) the retweets of all the tweets created by #FooWebsite.
For the moment, I think of using a cronjob that requests Twitter every minute to get info (number of retweets) about those tweets as I have their IDs.
Is there no subscription/callbacks like on Facebook API ?
I'm using PHP5.5 on Unix/Apache.

If you want to count Retweets as they happen in real time, the recommended way is to use the Streaming APIs.
In particular, the statuses/filter endpoint and its follow parameter will contain Retweets of any Tweet created by the user.
In order to distinguish these Retweets from the other Tweets streamed by the endpoint, you can rely on the presence of a retweeted_status nested object which will embed the original Tweet, allowing you to identify and focus exclusively on Retweets and count the ones you are interested in.
Please also note a retweet_count attribute value is attached to that node and represents, roughly, the number of times that original Tweet has been retweeted as of some time near when you were streamed the Tweet.

Related

Retrieving Facebook Page Statuses with PHP

Having trawled the web for days, I cannot find an up-to-date, working method to retrieve a list of the latest statuses on a Facebook page.
On the status section of the Graph API, I am greeted with "This document refers to a feature that was removed after Graph API v2.3"
I can't get file_get_contents to work on Facebook pages as I'm presented with a Captcha
It's for competitor research, I only actually want:
Post date
Number of Likes/Share/Replies
I couldn't care less for the status content itself, just the metrics around it.
A JSON object would be great, but I'll take anything at this stage.
Anyone else managed to get this sort of data or know a way to use file_get_contents on Facebook pages?
Thanks.
A status is just a certain kind of post – so all you need to do is request the page’s feed (resp. posts) instead, and then check if their type is status.
I've just tried to access the post object to get like/favourite counts .etc and get "[message] => (#12) singular statuses API is deprecated for versions v2.4 and higher"
You need to use the “full” post id as you get it from the /feed or /posts endpoint – the combination of page-id, underscore, post-id. (At least that’s the current format, but someone from Facebook told me we should not rely on that, it might change at some point. Best if you really just use the full id, as the endpoint returns it.)
And since you are interested in overall number of likes only, not the individual likes, you could make a request like this,
{full_post_id}?fields=likes.summary(1).limit(0)
That requests the summary (contains total counts), and limits the number of individual likes returned to zero (so as not to request any unnecessary data.) It works the same for comments. But I think for shared posts there is no such counts, you will only get a list of posts (which might not be all, but only those you are allowed to see.)

get recent tweets from twitter using API 1.1

I want to get recent tweets from twitter using API 1.1 .
I just don't want to get it only for current user or user's followers. I want to get all the tweets from all the users.
Is there a way by which I can get all user's tweets.
Is there any limit for this type of API call?
I want to fetch all the tweets at the application level, that means I won't be having any user token. How I can do this?
EDIT:
I found that we can use SEARCH API to search recent tweets using this
https://dev.twitter.com/docs/api/1.1/get/search/tweets
But In this API we have to pass the q parameter to search. But what if I don't want search based on specific parameter. I just want all the tweets from last 24 hours.
Is there way where I don't have to pass q in search API?
You want to call
https://stream.twitter.com/1.1/statuses/sample.json
This will allow you to get a random sample of the most recent tweets made by all users.
I am pretty sure there isn't any way to get all the tweets from all users at an application level. What you want to do is have your application store a version of each users tweet in a DB and then query the DB for that information. This approach also doesn't come with any call limits.
You look at a list of the available Twitter API v1.1 calls available in its REST API at:
https://dev.twitter.com/docs/api/1.1
The only application level call is:
GET application/rate_limit_status

Twitter API Rate Limit for Multiple Users

I am writing a PHP-based application using the Twitter API. Up until now I've been using the REST API via a GET request on a PHP page. However, as my app scales, I can easily see it going over the 150 requests-per-hour limit. Here's why:
I have categories of topics, each which periodically poll the Twitter API for tweets around a topic. For example, I have: mysite.com/cars, mysite.com/trucks, etc. A user can go to either page. When he is on the page, live, refreshing updates are pulled from Twitter by making an AJAX call to a PHP page I've set up. The PHP page determines which category the user is coming from (cars, trucks), polls Twitter for search results, then returns the JSON to the category page. This sounds confusing, but there are a number of unrelated reasons I need to have the intermediate PHP page.
The problem is that since the PHP page is making the requests, it will eat up the rate limit very quickly (imagine if there were 20 categories instead of just cars and trucks). I can't make a single call with multiple parameters because it would combine multiple categories of tweets and I'd have no way to separate them. I can cache results, but if I did, the more categories I add, the longer each would have to go between API calls.
So how can I approach this problem? I looked at the streaming API, but it's only for oAuth'd users and I don't want my users to have to log in to anything. Can I use the stream on the PHP page and then just make continuous requests each time the category page polls the PHP page? Thanks for any help!
a) You don't have to use your websites user's oAuth credentials in streaming API - just your's:
get them somewhere in dev.twitter.com and hardcode them. Your users won't know there is any oAuth going on backstage.
b) Don't use anonymous requests (150 per IP per hour) use oAuth requests (350 per oAuth per hour). You don't have to ask your users to sing in - just sign in few (1 is sufficient for start) your private twitter accounts. If you don't like creating twitter login functionality, you can get credentials for your twitter account to your twitter application in dev.twitter.com .
c) As #Cheeso mentioned - cache! Don't let every pageload make twitter request.

Retrieve complete Twitter timeline

we are working on a PHP webservice which is intended to retrieve a user's twitter timeline.
Now comes the problem, this is the URL we use: "http://api.twitter.com/1/statuses/user_timeline/$user.json?count=$num&include_rts=1 where $user is the user (^_^) and count the number of tweets to retrieve but it only shows me the tweets generated by the user or the ones reteeted by him.
I need ALL tweets that appear on his timeline, means the one he tweets and the ones people he is following tweets.
Is there any parametermissing in the URL above or do I have to use another method instead?
Thanks in adavance.
I answered a very similar question, it would apply in your case too..
use Twitter Counter as Twitter only supplies you with numbered I.D's rather then detailed info about followers.
Counting a Group of Twitter Users' Followers
MyAccount > MyFollowersAccount > followers_count
What I would do is this,
run the Twitter API method GET followers/ids
https://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name=twitterapi
to get the ID's of the followers of screenname X
and then switch over to Twitter Counter which will give you a more
detailed list and information about the followers, followers
specifically. Also, this could be a way to split up the two calls so
you won't be blocked by a rate limit problem on one end.
http://twittercounter.com/pages/api?ref=footer

Multiple twitter users' feed on one site without reaching the rate limit

I have a large number of twitter users I wish to sydicate onto a website using PHP and caching the tweets in MySQL. However I seem to be stumped by the rate-limit problem when ever I access the API. Every request I make to every user seems to count as a request, which stands to reason.
I notice other sites* doing this exact thing successfully. How are they getting around this, are they simply whitelisted, or is there a technique I'm missing?
*http://www.twackle.com/NFL/Aaron-Rodgers_1/tweets
The streaming API is what you are looking for, and more specifically, the filter method. Filter, at its least-privileged level, will allow you to follow 5,000 users in realtime, without them having to authorize your app, and you can track up to 400 keywords using this method as well.
Now, if you want historical tweets as well, you will have to pull those from the REST API (the streaming API's count parameter doesn't really help here), but since you can only retrieve the last 3200 tweets for a user via the REST API, you can pretty much backfill all available tweet history with 16 calls to statuses/user_timeline by passing in a count parameter value of 200 and paging accordingly.
http://api.twitter.com/1/statuses/user_timeline.json?screen_name=barackobama&count=200&page=2
http://api.twitter.com/1/statuses/user_timeline.json?screen_name=barackobama&count=200&page=3
http://api.twitter.com/1/statuses/user_timeline.json?screen_name=barackobama&count=200&page=4
With your 350 calls per hour per single Twitter account, you could backfill approximately 22 full user timelines per hour.
On the implementation side, you'd probably be interested in Phirehose, a streaming API client interface for PHP.
try to auth first, before get the tweets. that should increase the rate limit
A simple method of combining multiple user_timelines is to create a Twitter list and use GET /:user/lists/:id/status. That single API request will return the most recent tweets from all users on the list.

Categories