how to get user profile information from twitter using api in php?I have Consumer key,Consumer secret,Access token,Access token secret.
Related
I've noticed some people storing token and secret key in a user table after a user connects the the app using facebook login.
But I was just wondering, are these values changed constantly or not? Also, are they there to keep the login live or anything?
The Facebook API uses OAuth 2.0. Once a user has granted your application privileges to their account, FB sends you an authorization token that your application needs to store. The reason being is that you need to send that token every time you make a FB API request on behalf of that user. FB checks to see if the token is still valid and if it is then it allows the request to be processed (E.g. making a post to the user's wall).
If you look at the Graph API Explorer, you will notice the "Access Token" field at the top. Click the "Get Access Token" button to generate one for your own account so you can make test calls on behalf of yourself.
My goal is to search all users matching a specified name without the need for the user to be logged in with facebook. To accomplish this I did the following:
I created a Facebook App.
By using PHP I obtained the App access
token.
The problem is when I execute the api call:
"search?q=$name&type=user&access_token=$app_access_token";
I get the following result: "(#200) Must have a valid access_token to access this endpoint"
The question is, can I search users matching a specified name with my App Access Token or do I need a User Access Token?
You need a user access token (can be you as a user).
I am having a problem obtaining the twitter users access token and secret token without sending a username and password. I would like to get the access token by just sending the twitter_id, once the user has already authenticated my application before.
So the scenario is:
A user logs into my site (using custom login), he already gave my application permission to read/write his tweets. Now I need to load this users access token and secret access token.
Database:
CustomUID : 1 , Twitter_ID: 123456.
So Since I know CustomUID 1 is logged in, I need the access token/secret from Twitter_ID:123456.
The Problem is I canĀ“t find an API function that would let me get the access token without being redirect to Twitter Callback function (Twitter landing page), where the user has to type in his/her username and password, once again because the Request Tokens are obtained by the URL.
How can I solve this problem? I am used to the Facebook API, where user which have already authorize my app, allow me to receive their accesstoken just bei sending getAccessToken($ID).
Thank you very much for help!
You have to save, possibly in your DB, the OAuth token and access token after the first time the user authenticates. Then retrieve the token the next time you need to perform a query on behalf of that user.
I want to tweet on behalf of user with OAuth, but when user uses the application then tweet goes.
I wanna tweet on user's timeline when I want to. Is this possible?
This is the question that i hit my head on the wall for several days. But finally i got it.
TWITTER CONSUMER TOKEN
TWITTER CONSUMER SECRET
USER TOKEN
USER SECRET TOKEN
These are the things we need to post a tweet on behalf of user, and in this, TWITTER CONSUMER TOKEN and TWITTER CONSUMER SECRET should be created by the admin of the twitter app for whom/which requires permission to post on user behalf. And the USER TOKEN and USER SECRET TOKEN are the things that you need from user to post a tweet on his behalf. You can get this by using getRequestToken() function of OAUTH. To know how to use this function, please check redirect.php in twitteroauth written by Abraham here. And after getting USER TOKEN and USER SECRET TOKEN you can use your TWITTER CONSUMER TOKEN and TWITTER CONSUMER SECRET with the user's user token and user secret token received from the api to post on his/her behalf. Thats it!
But user can revoke the access anytime by visiting,
https://twitter.com/settings/applications and click on "Revoke Access" button next to your app.
With Twitter yes you can. When a user signs on your application via Twitter, just be sure to store their token and secret in a database for example, in order to authenticate as them in the future.
$twitter->setToken($_GET['oauth_token']);
$token = $twitter->getAccessToken();
$_SESSION['oauth_token'] = $token->oauth_token;
$_SESSION['oauth_secret'] = $token->oauth_token_secret;
Now store those Session variables and you are good to go. Note that $twitter is simply a wrapper class to work with Twitter's API.
So I want people to be able to login to the site via Twitter. For facebook I store the facebook id and the access token. In twitter from what I gather I need to store the twitter id, access token and secret token? Is that correct if I want to do things such as post to a twitter feed? Im using the twitter php sdk
I believe you only need the access token and the secret token (the twitter id is not required).
Actually, now that I think about it, since you are using Twitter for login, the Twitter id would be required too (for login purposes, not posting to Twitter).
See: Twitter API - Making a resource request on a user's behalf