PHP Classes

Twitter asks for Authorisation

Recommend this page to a friend!

      PHP OAuth Library  >  All threads  >  Twitter asks for Authorisation  >  (Un) Subscribe thread alerts  
Subject:Twitter asks for Authorisation
Summary:Twitter Authorisation page problem
Messages:6
Author:Martin Pitt
Date:2014-12-04 09:34:11
 

  1. Twitter asks for Authorisation   Reply   Report abuse  
Picture of Martin Pitt Martin Pitt - 2014-12-04 09:34:11
Hi Manuel,

Am I doing something wrong?

I am using your twitter script to post a message and a image to my twitter feed. The script itself is working fine, both the message and image are being uploaded fine. Excellent.

However, I am being asked every few hours to login/authorise my script via a Twitter page that pops up. Is there anyway this step can happen automatically?

I've added into the script my client_id and client_secret:

$client->client_id = ' xx HERE xx '; $application_line = __LINE__;
$client->client_secret = ' xx HERE xx ';

In other scripts I've used, I have also been asked to fill in oauth bits and generate these on the Twitter Application page. However, for your script, I've not done this, these 2 boxes remain blank on the Twitter Application page. Should I have generated some oauth bits too and if so, where do I place them in your script?

Kind Regards

Martin

  2. Re: Twitter asks for Authorisation   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-12-04 10:17:18 - In reply to message 1 from Martin Pitt
Twitter tokens are not known to expire. To keep using the tokens you need to store them in some persistent storage like a database.

The base OAuth class stores tokens in sessions. Sessions are only valid while the user is access the Web with the same browser. By default sessions die after the user closes the browser. Could that be your problem?

  3. Re: Twitter asks for Authorisation   Reply   Report abuse  
Picture of Martin Pitt Martin Pitt - 2014-12-04 12:41:23 - In reply to message 2 from Manuel Lemos
This sounds like what is happening.

Do you have a script that will bolt onto the login_with_twitter that makes available access to a MySQL database?

I am struggling to find anything in your published docs.


  4. Re: Twitter asks for Authorisation   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-12-04 20:24:41 - In reply to message 3 from Martin Pitt
Yes, try the mysqli_login_with_twitter.php script, its the same thing but it uses a sub-class that stores tokens in a MySQL table using MySQLi extension.

phpclasses.org/package/7700-PHP-Aut ...

There is an article that explains it better. It mentions Google, but it is the same for Twitter or anything else.

phpclasses.org/blog/package/7700/po ...

There are few details because when it authorizes an user, it associates with an user record in your database with id set to 1. You need to change that to have different records for different users.

You need to concentrate to get this right. Just let me know if you are not sure about how to do it right.

  5. Re: Twitter asks for Authorisation   Reply   Report abuse  
Picture of Martin Pitt Martin Pitt - 2014-12-05 13:26:03 - In reply to message 4 from Manuel Lemos
Thanks Manuel,

This will give me some weekend reading :)

I quickly noticed that in the mysqli_login_with_twitter.php file, the following code is missing. Can this be added?


/* Tweet with an attached image

$success = $client->CallAPI(
"https://api.twitter.com/1.1/statuses/update_with_media.json",
'POST', array(
'status'=>'This is a test tweet to evaluate the PHP OAuth API support to upload image files sent at '.strftime("%Y-%m-%d %H:%M:%S"),
'media[]'=>'php-oauth.png'
),array(
'FailOnAccessError'=>true,
'Files'=>array(
'media[]'=>array(
)
)
), $user);
*/

  6. Re: Twitter asks for Authorisation   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-12-05 14:02:10 - In reply to message 5 from Martin Pitt
That is just some example code that is commented. You can do whatever API calls you want from your own applications.