First of thanks for the fantastic code, it works like a dream.
I've used the mysqli_login_with_twitter.php, however can you tell me how to specify the 9 digit user id (in the php code below) so it can also be saved to my mysql database? It currently shows as 1 for every member in the mysql database and as 0 when I tried to login on my iPhone?
* Once you were able to access the user account using the API
* you should associate the current OAuth access token a specific
* user, so you can call the API without the user presence, just
* specifying the user id in your database.
* In this example the user id is 1 . Your application should
* determine the right user is to associate.
$success = $client->SetUser(1);
Manuel Lemos - 2013-07-15 20:59:49 - In reply to message 1 from Sam Tattersfield
It is up to you to figure the user ID.
Either you already have a record of the user in your application database or you need to create a new one from the user data retrieved from Twitter.
Twitter accounts have some unique user identifier that you can use to establish that relationship. So, you need to have a table that determines which Twitter user id corresponds to your application user id in the database.
You need to check that table. If the Twitter user id exists in the table, get the respective user id of your application and pass it to SetUser. If it does not exist, you need to create a new record. In that case use the new record user id to pass to SetUser.
Sam Tattersfield - 2013-07-19 21:19:20 - In reply to message 2 from Manuel Lemos
Thanks Manuel, Sorry to be a pain with all the questions.
Do you have an example of the table format that I should use in my application to check the user id currently in my mysql database?
I already have a record of the user (my own twitter account) in my application database, however when I log in with my Twitter account again (say the next day) the current php code creates a new record from the data retrieved from Twitter, so a duplicate record of my Twitter credentials. I thought if I signed in with my Twitter account again it would ignore my details as they already exist in the mysql database (maybe update them if my tokens had been reset) and direct me back to my application?
Manuel Lemos - 2013-07-20 09:50:12 - In reply to message 3 from Sam Tattersfield
You can use any database table format your application needs. You just need create records in it if the user is new or look it up some how to find what is the user id associated with the Twitter user.
When the user is already logged in your site, you probably setup a session variable in your site, so you should not be using the OAuth to identify the user because he is already identified. That is the way to avoid the OAuth classes to create duplicated user records.