How to index tweet as soon as it is posted? - php

Is there a way to know that a user posted a tweet as soon as he does it? Maybe Twitter can ping your app or something?
What if I have a user base of 100.000 users? It's hard to check constantly all.
Thank you,
Andrew

Check out the Streaming API, specificially user streams: https://dev.twitter.com/docs/streaming-api/user-streams

You would use the Streaming API for this case. This is exactly what this does, you open a firehose and Twitter pings your application with new tweets every time there is an update based on your query. If your using PHP, you can make implementing the streaming API easier by using the 140 framework.
from streaming API method doc
The default access level allows up to 400 track keywords, 5,000 follow
userids and 25 0.1-360 degree location boxes. If you need elevated
access to the Streaming API, you should explore our partner providers
of Twitter data here.

Related

how to post on google plus page stream using php/curl?

I want to post on google plus page stream using php, I checked google plus api but didn't found anything, read a post where it was saying that you can't post because google only provided read permission. When I googled I saw nextscripts SANP API to post on social networks.
If google only provided read permissions then how nextscripts is able to post?
SNAP is a paid API & I want to create my own code to do the same.
Is there anything I am missing. please guide me.
Short answer: There is no way to create a post that appears in a Google+ stream.
Medium answer: Google doesn't provide an API to post to a "normal" user's page. There are APIs that allow a website to let a user post something, and they can suggest text to post, but the user must take an explicit action. There have been attempts to use unauthorized APIs to do this, but they try to intercept the above procedure and aren't reliable. Depending on your exact needs, there are other alternatives as well.
Long answer: Depending on your exact needs, there may be some APIs which can help. But keep in mind they only apply to specific, sometimes very narrow, circumstances:
Are you trying to post to a page, not a user? There is the Google+ Page API which is available to partners only. This may be what the netxtscripts SNAP API is using - I don't know. This is what HootSuite uses, for example. You can request access at https://developers.google.com/+/api/pages-signup, but they don't approve many applicants.
Are you trying to post on behalf of a Google Apps user for other users in the same domain to see? If so, there is the Domains API at https://developers.google.com/+/domains/
Are trying to post an activity or action? Like the user listening to a song or eating at a restaurant? You may benefit from App Activities with the Moments API. These don't go directly into the stream, but are available through Search, in the user's profile in some limited ways, and they can reshare them into the stream if they wish. https://developers.google.com/+/features/app-activities
Let a user post to their stream from a web page? This still requires specific action by the user, so they have to approve what you're saying, but you can use something like normal share, +1, or interactive post buttons. https://developers.google.com/+/features/interactive-posts
You just want your server to post a plain old normal message to a normal user's stream without a person having to do anything? You can't do that.
There is still no way to post on a Google+ stream using an API. For details on what you can currently do with the limited API you can look at Google+ api
There is an issue request for this from as far back as 2011: Write access to the streams

user's last login date and time facebook graph explorer

I have search a lot on this site and google to get the last login date and time of a particular facebook user from user id using the graph explorer. However, could not find a relevant article.
I have 20+ employees working in my office and I do not want them to access facebook during shift timings. I have their user ids with me. Is it possible to check when did they last login/logout or performed any activity on facebook using their FB UIDs using a php/mysql or any other way or just by using the graph explorer?
I read some articles that had fql options but i could not try those as fql is depreciated. Any help here would be appreciated.
Thanks
Did you meant to use a Graph or Graphic ?
Using a table to log-in when your users accessed Facebook will be simpler.
You'll have to apply a filter to remove results outside the shift timings.
Once you are done with it, creating a bar graphic will be an easy solution.
If you want to use the Graph API, you need to make sure that your employees log-on onto your application and give their consent.
You should check : https://developers.facebook.com/policy before trying anything.
Only use our SDKs to develop and distribute apps for use with the
Facebook Platform. You may also distribute any code libraries or
sample source code included in the SDKs for inclusion in such apps.
Use simple network functions like logs to collect data.
Enabling a Firewall is better than making Facebook accessible in those shift hours.
If you meant Graph API, it's a social graph explorer. It's meant to show all the relations between the users. I am not sure how far it deviates from a graph, neither if it has some visualization capabilities.
Using the Graph API to monitor your workers might be a grave legal infringement. There are many laws protecting privacy at work. The Graph API can give all kind of information. I would not suggest to use any kind of solution that gives access to some sensitive data...
Logging all the Connections going to FB would be the only choice.

PHP twitter Hometimeline

I making a php server/page which is supposed to capture a users twitter feed and then provide it in a JSON format to another application and/or mobile device in JSON format.
Twitter provides it's data already in JSON format by using .json after the timeline url. But this is limited to 150 requests/hour which can be a problem being on a shared hosted server.
If been trying to use the twitteroauth php library with API keys. Before I can start communicating with the API I always need to sign in with a twitter account. Using the API is limited to 350 request/hour.
Is there a way to use the library not needing to log in to capture the timeline?
Or what is a better way to achieve my goal, creating a php-page providing me the timeline on request?
If I understand the question correct, the problem is that you make to many request to the Twitter API that doesn't require log on. In that case, if you don't want to use the API that require login, I guess you could implement some caching. Let your server run a cron every minute that check the Twitter API for new tweets, and store the tweets in a database or a textfile.
Then, when a user request your page for JSON, you read from your cache instead of going straight to the Twitter API every time. That way you will save a lot of traffic between your server and Twitter, and you would still be very close to real time when it comes to up-to-date tweets, as you with 150 requests/hour could update your cache every 30 seconds or so.

Facebook API Responses Very Slow (oAuth)

I am doing some benchmark testing on my web app and notice that the responses from Facebooks API are a lot slower than Twitters.
** For the record, I am using the twitter-async library for Twitter API integration and Facebooks own library here
With the Twitter library I can save an oAuth token & secret, I then use these to create an instance and make calls, simple. For Facebook, unless I ask for offline_permission, I must store an oAuth code and recreate an oAuth access token each time the user logs into my app.
Given the above I can:
Retrieve a Twitter users timeline in 0.02 seconds.
Get a FB oAuth Access Code in 1.16 seconds, then I can get the users details in 2.31 seconds, totalling 3.47 seconds to get the users details.
These statistics are from using functions Facebook has provided in their PHP API library. I also tried implementing my own CURL functions to get this information via a request and the results are not much better.
Is this the same kind of response times others are getting using the Facebook API?
Besides requesting offline permission and storing the permanent access token, how else can I speed up these requests, is the problem on my end or Facebooks?
Thanks,
Chris
I also have the experience the Facebook API is quite slow. I believe the facebook PHP API does not much more than wrap around CURL in the case of API calls so it makes sense that this didn't improve the speeds.
I work on a canvas page, which means for existing users, I get an access token and fb_UID as he/she comes in. At first, I did a /me graph call and sometimes a /me/friends. The first takes like 0.6 secs, the second usually a bit more. So in that case I can (to some extend) confirm your findings.
That's why I've now switched to storing important stuff locally and updating it only when needed (real time update API). Basically, I don't need any API calls during 'normal' operation.
I realize you are probably integrating FB on your own page, and perhaps use a bit more info than just name, fb-UID & friends, and that this solution is not totally answering your question. But perhaps it can still function as a small piece of the puzzle ;)
I am looking forward to other perspectives on this as well!
My application calls multiple URL's from Facebook. It does take some time :/
This is why I decided to write a function which stores the results in $_SESSION so I can use it again later, along with a timestamp to see if the data is too old.
This doesn't solve the actual problem, it just saves you having to keep fetching it.
What I like to do for end user experience, is forward them to page with a loading .gif - then have javascript request the page that actually fetches data. That way, the user remains on a loading page with a nice gif to stare at, until the next page is ready.

How can my web app retrieve Twitter user photos without hitting the API limit?

I am writing a web app that needs Twitter user's profile photos only. I retrieve these by parsing the users/show XML unauthenticated API call (http://apiwiki.twitter.com/Twitter-REST-API-Method:-users%C2%A0show):
$twitterXML = simplexml_load_file("http://twitter.com/users/show/".$twitterUsername.".xml");
In my testing I have been hitting the Twitter API rate limit. When I retrieve the user photo URL in the above way is the Twitter API rate limit imposed on the IP address of my server so that anyone who uses my web app contributes to the 150/hour limit? Or is that limit imposed on the IP address of the user who is visiting my web page?
Is there any way to retrieve a user's profile photo without being affected by the rate limit?
There is a number of ways you can do avoid the rate limiting.
You can use Twavatar and not even hit Twitter directly.
http://twitteravatar.appspot.com/
You can create an extra Twitter account to use just as a bot to authenticate with when calling the API giving you an additional 150 hits an hour.
You can get your IP whitelisted in which case you will be able to make 20,000 request an hour. http://twitter.com/help/request_whitelisting
You can have users authenticate with twitter when they visit your site and push the hits to the rate limit off on them. Sign in with Twitter is a good way to achieve this: http://apiwiki.twitter.com/Sign-in-with-Twitter
You can read more about Twitter's rate limiting on their website.
http://apiwiki.twitter.com/Rate-limiting
It's your server that fetches the XML file, so it's the server IP address that is getting throttled. One solution would be to use some form of caching so you reduce the number of requests that your server is sending.
I'd try caching the users's photo for a period of time or persisting the photo on your end so that you don't call twitter each time.
Here's an article on caching with PHP: http://www.developertutorials.com/tutorials/php/php-caching/page1.html
I am not extremely familiar with Twitter's API. My first question is whether your users are requesting similar profiles? If there is any similarity between your users' requests for photos you might consider caching profile photos and checking the cache prior to making a request to Twitter.
Try asking Twitter to remove the rate limit for your app. If you explain why you need it maybe they can help you.

Categories