Reputation: 47
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?
Upvotes: 2
Views: 1730
Reputation: 10621
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.
Upvotes: 3
Reputation: 3346
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.
Upvotes: 1