I want to show my latest tweet in a web page. My tweets are private for some reason and I should login to Twitter. I know that the basic HTTP authentication was deprecated in August 2010. How can I provide authentication in my PHP code to fetch private tweets (or userTimeline if I'm not mistaken)?
I've searched but unfortunately didn't find anything useful! :( Thanks in advance for your help!
Jan, I heard about ZendFramework while I was searching for the answer but It's complicated for me.
I found the solution here that illustrates how I can use OAuth based on Abraham’s Twitter OAuth library.
The key note is that I stored my 'oauth_access_token' in a database or somewhere else immediately after first login via my twitter credential. Then I remove the code which allow users to login to twitter and reuse stored credential to fetch the latest tweet by using $user->status->text variable.
It's a geeky job. It maybe has some potential security flaws but I'm not sure! ;)
By the way, Thanks a lot for your reply, Jan! :D
Authentication to Twitter is done via OAuth. A pretty simple way to access your Twitter account with PHP is using the latest version of ZendFramework. It will be required to register your app on twitter, which allows you to generate an oauth token. This token can be used to access your private twitter feed.
See documentation of Zend_Service_Twitter and Zend_Oauth_Consumer.
Here http://framework.zend.com/manual/en/zend.oauth.introduction.html you will find a pretty good introduction of using Zend OAuth together with twitter (note that the address used in the $config array has to be api.twitter.com/oauth and NOT twitter.com/oauth )
However, you can also make your Tweets public in your twitter account settings (Settings -> Account -> Tweet Privacy -> Uncheck "Protect my tweets"). Then your tweets will be available on the public timeline (not at once, you may have to wait a bit).
Hope that helps!
-Jan
Related
I have a protected twitter account but I want to be able to show a list of my most recent tweets on my website.
I'm prepared to dive in to the twitter docs but I just wanted a heads up to know if its possible?
Would my script have to autenticate with my account or is there a way to allow access to my twitter account from a particular IP?
Thanks
Yes, definitely possible. I don't know if there is a simpler solution, but one way would be to create a new app on Twitter which your account authorizes. In the authorization process, Twitter will give you access tokens for your specific account. Store your access tokens in a database. Read your tweets from a PHP widget say, which uses the Twitter PHP API, and uses your access tokens to display it.
When you are retrieving your tweets, it doesn't matter if it is protected or not as long as you have authorized that specific application.
Simply put, the widget that displays your tweets is a Twitter application that you have authorized. (one-time authentication)
Well I don't think so you can read anything from Protected account.
I was reading few articles about the same issue and here is the alternative solution if you would like to give a try. (I personally didn't tried it so leaving up to you to give shot)
http://www.ehow.com/how_6474863_protected-twitter-updates.html
I am trying to get a list of all Google Apps users of a domain onto a public PHP website (without visitors of the site needing to login or do anything). I have a basic understanding of what needs to happen but can't quite piece it all together. It can't be as hard as it seems to me... could it?
Authentication and Authorization:
I'm pretty sure it needs to use OAuth 2.0 ... but am unsure whether it needs 2 legged or 3 legged. I got another section of the site working with ClientLogin but that won't pull in Google Apps profiles, only user's first and last names (I need the other profile fields). I have set up the API access within the account and have that side of things all set (I believe).
I have found this page, which shows how to construct a URL request to get all Profiles (in every language except PHP of course) but don't understand how to implement this.
http://code.google.com/googleapps/domain/profiles/developers_guide.html
I also tried this example but it just gives me a 401 after I enter the credentials. http://gdatatips.blogspot.com/2008/11/2-legged-oauth-in-php.html
I don't know which frameworks or includes are needed to accomplish this either. I have tried zend, OAuth.php and a whole bunch of other bootstraps... but keep getting lost as to what each is doing.
If someone could help me by outlining:
Which files/framework I need to upload and include as a bootstrap
What variables within those files I need to update with the Google credentials
How I integrate the Google Profiles "Retrieve all Profiles" request with PHP
An ELI5 (explain it like i'm 5) overview would be very much appreciated... I'm sorry for my apparent incompetence, but I have been reading articles for nearly a week and have not gotten anywhere.
Thank you in advance for any help provided.
Good question.
You'll need to implement the Google OAuth 2.0 process as it's described here (experimental?), because someone (you) will need to give your app the initial permissions to access Google Apps API. Steps are:
Register your domain with google (don't remember the link)
Redirect/send browser to an authentication url: https://accounts.google.com/o/oauth2/auth, with the appropriate request params (see the first link). You'll need access_type=offline, your scope would be https://apps-apis.google.com/a/feeds/user/
Get a code back, then exchange for a refresh_token, an access_token, and a value specifying when the access_token will expire. Store these in a database
Whenever you need to make an API call, check if your access_token has expired or not, and refresh when necessary, which is what the refresh_token is for. The refresh_token is valid as long as you don't revoke the access you gave to the app.
OAuth Playground helps a lot. Good luck.
I am curious to know how to authenticate the user with twitter and after successful login, i need the email of the user... how can it be done?
Heard that twitter does not support openid.... any alternate solution ?
Just to update this issue, it is now possible (from April 2015).
You can send a support ticket to Twitter to whitelist your app to make it possible to ask for an email. Then, after an user connects their account, you need to make a GET request to verify credentials with the "include_email" option set to true.
It is explained in more detail in the second link.
Check out this article and try this search.
Twitter supports OAuth, and I am myself having trouble with it (I am writing a Python script app). A switch to xAuth is possible.
"Mobile and desktop applications are also given the opportunity to use xAuth, a means to exchange a login & password for an access token. To use xAuth, send a request to api#twitter.com with plenty of details about your application and why xAuth is the best choice for it." - http://dev.twitter.com/pages/auth
Late answer, but I hope it will help someone.
There is no way to obtain the email from the API.
See the doc there : Twitter doc
Other post relating that : SO post
The link provided in tarantinofan's answer is quite old, but the principles are there, as an explanation on how OAuth works.
Twitter API cannot provide Email address so you cannot get it from twitter API
(See Doc of twitter api)
you can get it from user after log in or try another way
I was reading some stuff about the YQL api that Yahoo! has provided, I am not sure, but it appears to be a collection of lots of third party api into one common language, right?
what I don't get is how to make the facebook login through it so I can get the user profile data...
My project is to add a facebook(and other social networks) form login, because the website won't have his own login, people will have to use a social network to link in. Then I thought the YQL would help me out with this task so I wouldn't have to develop lots of functions to each one of the networks.
Reading this http://developer.yahoo.com/yql/guide/yql-code-examples.html#sdk_yql, I understood how to make a Yahoo login so I can access some private data, but couldn't find how I could do it with facebook and others
So my question... Can YQL help me with this? Can you give me a simple example of a facebook session using it within PHP? Are there alternatives to aid me in this task?
thanks,
Jonathan
Yes , using YQL you will be able to do this task .. you can look at this demo http://demo.tutorialzine.com/2010/05/showing-facebook-twitter-rss-stats-jquery-yql/demo.html. Also if you are going to only use Facebook authentication , then there is no need for YQL you can do it using http://developers.facebook.com/docs/authentication/
I highly doubt that YQL has an API that gives a free hand with facebook login. You have to consider how a login works. You send POST data to a web server containing client-side password hashes and encryptions, as well as other kinds of identification. YQL has no way to "standardize" logins - it would have to make a new API for every popular web site.
I used cake php with twitter datasource to post some info on a certain twitter account. Twitter changed the authentication method towards oauth.
I can't find an example of a cakephp app, where a certain message is posted in a certain twitter account. For example when publishing an article in the site, I want site's twitter account to get updated.
I have read some examples but in these the user accessing the page gets redirected to twitter to be authenticated and to publish something on his/hers account, which is not want I want.
Anybody has an example on that?
thanks a lot.
Have a look at Using one access token with OAuth in the Twitter documentation, it describes a single-user use case and avoids the redirect.
Hm, I do not know if this helps you, but do you read the article from neil crook? cakephp-oauth-extension-to-httpsocket
I think for the first time the user get redirected to twitter to authorize the application... After that you save ‘oauth_token’ and ‘oauth_token_secret’ for further access to the Twitter Api...
But i must say that i have not tried it yet...
Maybe the tipp from David Yell in this question thread LINK helps