Post a Tweet to User's Account - php

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.

Related

How to get permanent access token for microsoft outlook api

I have set scopes as follows:
openid profile
offline_access
User.Read Mail.ReadWrite
Mail.Send
Calendars.ReadWrite
Contacts.Read
I want a permanent access token so that I don't need to login again and again.
Help me out, how can I use a token in the login api to get permanent access?
Thanks in advance.
Graph API provides two authentication flow:
1. Get access on behalf of a user
2. Get access without a user
If you want to run the Outlook API in background service(not all app need user signed-in, based on actual demand), you can use the authentication flow #2. By using this way, end user do not need to request Token explicitly, so it look like permanent access token, until the Microsoft/Azure need the admin consent again.
If you want to run the Outlook API just for signed-in user, you can use the authentication flow #1. After get an access Token, store the access Token and Refresh Token in the Token-cache and use the refresh Token to request new Token while the access token lifetime expires. If both access/refresh token have expired, the user need to sign-in again to re-grant permission.

Facebook Social Graph - why storing token and secret when login

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.

get user profile information from twitter through Access token in php

how to get user profile information from twitter using api in php?I have Consumer key,Consumer secret,Access token,Access token secret.

Twitter API: Get Access Token without sending username/password

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.

Twitter API - What to store on app side?

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

Categories