[twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-08-10 Thread Skygazer
Hi everyone,

I'm in the same boat as Paul G. My company publishes updates to
Twitter whenever we post a new story. To date our code using basic
authentication was working great. Now we're switching over to OAUTH
using Abraham Williams library. I setup an app on Twitter's
development site, got my keys and tokens and tried using the PHP
twitteroauth library, but on my test server I can't even get the
example to work. I get the Could not connect to Twitter. Refresh the
page or try again later message. I've got the library running on my
Mac Pro with Apache running on a port-forward.

I'll note that when I created the app I used application type: browser
and callback url: blank

Any help would be appreciated. Code always welcome :-)

Marc

On Jul 22, 2:09 pm, Paul G p...@taosinteractive.com wrote:
 Hi Everyone.

 I've been puzzling overOAuthfor some time now with little insight
 into how to apply it to my situation.  If someone could nudge me in
 the right direction I'd be most grateful.

 What I am doing now is very simple.  Whenever my company publishes new
 content to it's websites, the companyTwitteraccount is updated to
 reflect it.   This is not an application that is open to public use.
 It doesn't require any browser-based login boxes or http redirects as
 part of the process.  In fact, such a requirement would prevent the
 function of my current routine.

 EXAMPLE:  (synopsis)
         require classes/Twitter.class.php;
         $PMTtweet = newTwitter($twitterunamePMT, $twitterpwordPMT);
         $PMTsuccess = $PMTtweet-update($thisTweet);

 My questions are:

 1. Do I need to upgrade toOAuth?
 2. If I need to upgrade toOAuth, can it be done in such a way as to
 work without browser login and redirect requirements? (as per example)
 3. If 2 is true, any tutorials that match that situation you can point
 me to?
 4. If 1  2,  where/how would I acquire the tokens necessary to useOAuth?

 Apologies for the basic questions.  I really did make an effort to
 ferret out the answers but all the examples I encountered were much
 more complex than my situation requires.

 Thanks

 Paul G


[twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-08-10 Thread Skygazer
I got my code working well enough to forge ahead on my own thanks to
the examples on Abraham's github wiki page 
http://wiki.github.com/abraham/twitteroauth/links

Marc

On Aug 10, 12:25 pm, Skygazer marc.bouc...@gmail.com wrote:
 Hi everyone,

 I'm in the same boat as Paul G. My company publishes updates to
 Twitter whenever we post a new story. To date our code using basic
 authentication was working great. Now we're switching over toOAUTH
 using Abraham Williams library. I setup an app on Twitter's
 development site, got my keys and tokens and tried using thePHP
 twitteroauth library, but on my test server I can't even get the
 example to work. I get the Could not connect to Twitter. Refresh the
 page or try again later message. I've got the library running on my
 Mac Pro with Apache running on a port-forward.

 I'll note that when I created the app I used application type: browser
 and callback url: blank

 Any help would be appreciated. Code always welcome :-)

 Marc

 On Jul 22, 2:09 pm, Paul G p...@taosinteractive.com wrote:



  Hi Everyone.

  I've been puzzling overOAuthfor some time now with little insight
  into how to apply it to my situation.  If someone could nudge me in
  the right direction I'd be most grateful.

  What I am doing now is very simple.  Whenever my company publishes new
  content to it's websites, the companyTwitteraccount is updated to
  reflect it.   This is not an application that is open to public use.
  It doesn't require any browser-based login boxes or http redirects as
  part of the process.  In fact, such a requirement would prevent the
  function of my current routine.

  EXAMPLE:  (synopsis)
          require classes/Twitter.class.php;
          $PMTtweet = newTwitter($twitterunamePMT, $twitterpwordPMT);
          $PMTsuccess = $PMTtweet-update($thisTweet);

  My questions are:

  1. Do I need to upgrade toOAuth?
  2. If I need to upgrade toOAuth, can it be done in such a way as to
  work without browser login and redirect requirements? (as per example)
  3. If 2 is true, any tutorials that match that situation you can point
  me to?
  4. If 1  2,  where/how would I acquire the tokens necessary to useOAuth?

  Apologies for the basic questions.  I really did make an effort to
  ferret out the answers but all the examples I encountered were much
  more complex than my situation requires.

  Thanks

  Paul G


Re: [twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-24 Thread Paul S Gutches



I follow that.

I was wondering if the creds needed to be in a session var or not.

I'll give it a try!

Thank you!


On Jul 23, 2010, at 11:00 PM, Abraham Williams wrote:


Hello Paul,

In redirect.php the request token (also called temporary  
credentials) are one use. After the user returns from twitter.com  
having authorized the application they are exchanged for an access  
token from Twitter which is long lasting and what you are after.


If the request token is not being saved/retrieved from sessions  
properly you can print it and the authenticate URL in redirect.php  
instead of automatically redirecting. Copy/paste the authenticate  
url into a browser window and authorize the app to access the user  
account. Then you can manually put the request token into the quick  
and dirty code instead of pulling from a session. Keep in mind that  
you can only use the request token once so if you don't print the  
access token the first time you will have to do it all again.


Abraham
-
Abraham Williams | Hacker Advocate | http://abrah.am
@abraham | http://projects.abrah.am | http://blog.abrah.am
This email is: [ ] shareable [x] ask first [ ] private.




Re: [twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-24 Thread Abraham Williams
The temporary credentials need to be store while the user goes to
twitter.com and authenticates. Sessions are awesome for this so I use it.
You can use other mechanisms if you want.

Abraham
-
Abraham Williams | Hacker Advocate | http://abrah.am
@abraham | http://projects.abrah.am | http://blog.abrah.am
This email is: [ ] shareable [x] ask first [ ] private.


On Sat, Jul 24, 2010 at 09:12, Paul S Gutches p...@taosinteractive.comwrote:



 I follow that.

 I was wondering if the creds needed to be in a session var or not.

 I'll give it a try!

 Thank you!


 On Jul 23, 2010, at 11:00 PM, Abraham Williams wrote:

 Hello Paul,

 In redirect.php the request token (also called temporary credentials) are
 one use. After the user returns from twitter.com having authorized the
 application they are exchanged for an access token from Twitter which is
 long lasting and what you are after.

 If the request token is not being saved/retrieved from sessions properly
 you can print it and the authenticate URL in redirect.php instead of
 automatically redirecting. Copy/paste the authenticate url into a browser
 window and authorize the app to access the user account. Then you can
 manually put the request token into the quick and dirty code instead of
 pulling from a session. Keep in mind that you can only use the request token
 once so if you don't print the access token the first time you will have to
 do it all again.

 Abraham
 -
 Abraham Williams | Hacker Advocate | http://abrah.am
 @abraham | http://projects.abrah.am | http://blog.abrah.am
 This email is: [ ] shareable [x] ask first [ ] private.





[twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-23 Thread Paul

Hi Paul,

Yep, was referring to the snippet.  I've just copy/pasted yours,
changed keys and callback URL and your code works for me.

I'm afraid the only thing I can suggest is to double-check your
consumer key/secret,

Cheers,
- Paul


Re: [twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-23 Thread Paul S Gutches



ok.

thanks for testing!


On Jul 23, 2010, at 4:58 AM, Paul wrote:



Hi Paul,

Yep, was referring to the snippet.  I've just copy/pasted yours,
changed keys and callback URL and your code works for me.

I'm afraid the only thing I can suggest is to double-check your
consumer key/secret,

Cheers,
- Paul





Re: [twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-23 Thread Paul S Gutches



Ok...

looks like there are others who received the same exception error when  
trying to generate an auth url.


So, I switched over to Abraham's routine, which worked, and the  
oauth_token and verifier came back, but sadly, a new exception was  
thrown in the twitter-async code I was still using to retrieve the key/ 
secret.


Right now I'm trying to use Abraham's twitteroauth to output the same  
info.  Is that possible?


I looked at the class source but they are different enough to make it  
opaque to me.   There is no equivalent setToken in twitteroauth.


Does anyone know how to get twitteroauth to spill the same beans? 
I'm so close, and yet so far!


for the intrepid, here are the async calls I'm trying to find  
equivalents for in twitteroauth


$twitter-setToken( $_GET[oauth_token] );
$token = $twitter-getAccessToken( array( oauth_verifier = $_GET 
[oauth_verifier] ) );

var_dump( $token-oauth_token, $token-oauth_token_secret );


thank you

Paul G


On Jul 22, 2010, at 5:53 PM, Paul wrote:


Hi Paul,


Is there a way to retrieve the consumer keys for the other Twitter
account I own without registering an app?


Yep, if you use that script given previously, just login to the other
Twitter account instead (with the same consumer key/secret.  This will
give you a different pair of tokens for the second account.

Initialise as in tweeting example with the new token.  Basically what
you're doing is authorising the same app for both accounts.

- Paul





Re: [twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-23 Thread Abraham Williams
This is quick and dirty and assumes that oauth_token and oauth_token_secret
are set in a session before you are redirected to twitter.com to authorize
the application.

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
$_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token = $connection-getAccessToken($_REQUEST['oauth_verifier']);
var_dump($access_token);

Abraham
-
Abraham Williams | Hacker Advocate | http://abrah.am
@abraham | http://projects.abrah.am | http://blog.abrah.am
This email is: [ ] shareable [x] ask first [ ] private.


On Fri, Jul 23, 2010 at 09:49, Paul S Gutches p...@taosinteractive.comwrote:



 Ok...

 looks like there are others who received the same exception error when
 trying to generate an auth url.

 So, I switched over to Abraham's routine, which worked, and the oauth_token
 and verifier came back, but sadly, a new exception was thrown in the
 twitter-async code I was still using to retrieve the key/secret.

 Right now I'm trying to use Abraham's twitteroauth to output the same info.
  Is that possible?

 I looked at the class source but they are different enough to make it
 opaque to me.   There is no equivalent setToken in twitteroauth.

 Does anyone know how to get twitteroauth to spill the same beans?I'm so
 close, and yet so far!

 for the intrepid, here are the async calls I'm trying to find equivalents
 for in twitteroauth


 $twitter-setToken( $_GET[oauth_token] );
 $token = $twitter-getAccessToken( array( oauth_verifier =
 $_GET[oauth_verifier] ) );
 var_dump( $token-oauth_token, $token-oauth_token_secret );


 thank you

 Paul G



 On Jul 22, 2010, at 5:53 PM, Paul wrote:

  Hi Paul,

  Is there a way to retrieve the consumer keys for the other Twitter
 account I own without registering an app?


 Yep, if you use that script given previously, just login to the other
 Twitter account instead (with the same consumer key/secret.  This will
 give you a different pair of tokens for the second account.

 Initialise as in tweeting example with the new token.  Basically what
 you're doing is authorising the same app for both accounts.

 - Paul





Re: [twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-23 Thread Paul S Gutches



Thanks Abraham.

I'm still a bit baffled, but I'm sure the origin is local, haha.

I used your testing routine with the Sign in to Twitter dialog to  
try to access the account token and secret for storage.   In your  
redirect.php file, it does look like you are setting session vars in  
there for the token and secret before the redirect to Twitter.


But it also says in your comments that those are temporary  
credentials.  I was confused by that, because it's my understanding  
they're not supposed to expire, which is how they can be used again  
for future access.   Do I have that wrong?   I'm looking for the  
credentials that developers are storing for re-use of their user's  
Twitter accounts.


Even though your redirect.php file is creating a session for the  
variables, when the callback to the quick and dirty code occurs, the  
variables are not accessible.   I get the below notices.


br /
bNotice/b:  Undefined variable: _SESSION in b/path/twittertest- 
oauth2.php/b on line b21/bbr /

br /
bNotice/b:  Undefined variable: _SESSION in b/path/twittertest- 
oauth2.php/b on line b21/bbr /

br /
bNotice/b:  Undefined index:  oauth_token in b/path/twitteroauth/ 
twitteroauth.php/b on line b118/bbr /

br /
bNotice/b:  Undefined index:  oauth_token_secret in b/path/ 
twitteroauth/twitteroauth.php/b on line b118/bbr /

array(1) {
  [ ]=
  string(0) 
}

Any advice for keeping hope alive?  :)

Thanks again

Paul G


On Jul 23, 2010, at 1:13 PM, Abraham Williams wrote:

This is quick and dirty and assumes that oauth_token and  
oauth_token_secret are set in a session before you are redirected to twitter.com 
 to authorize the application.


$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,  
$_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token = $connection-getAccessToken($_REQUEST 
['oauth_verifier']);

var_dump($access_token);

Abraham
-
Abraham Williams | Hacker Advocate | http://abrah.am
@abraham | http://projects.abrah.am | http://blog.abrah.am
This email is: [ ] shareable [x] ask first [ ] private.




Re: [twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-23 Thread Abraham Williams
Hello Paul,

In redirect.php the request token (also called temporary credentials) are
one use. After the user returns from twitter.com having authorized the
application they are exchanged for an access token from Twitter which is
long lasting and what you are after.

If the request token is not being saved/retrieved from sessions properly you
can print it and the authenticate URL in redirect.php instead of
automatically redirecting. Copy/paste the authenticate url into a browser
window and authorize the app to access the user account. Then you can
manually put the request token into the quick and dirty code instead of
pulling from a session. Keep in mind that you can only use the request token
once so if you don't print the access token the first time you will have to
do it all again.

Abraham
-
Abraham Williams | Hacker Advocate | http://abrah.am
@abraham | http://projects.abrah.am | http://blog.abrah.am
This email is: [ ] shareable [x] ask first [ ] private.


On Fri, Jul 23, 2010 at 14:23, Paul S Gutches p...@taosinteractive.comwrote:



 Thanks Abraham.

 I'm still a bit baffled, but I'm sure the origin is local, haha.

 I used your testing routine with the Sign in to Twitter dialog to try to
 access the account token and secret for storage.   In your redirect.php
 file, it does look like you are setting session vars in there for the token
 and secret before the redirect to Twitter.

 But it also says in your comments that those are temporary credentials.  I
 was confused by that, because it's my understanding they're not supposed to
 expire, which is how they can be used again for future access.   Do I have
 that wrong?   I'm looking for the credentials that developers are storing
 for re-use of their user's Twitter accounts.

 Even though your redirect.php file is creating a session for the variables,
 when the callback to the quick and dirty code occurs, the variables are not
 accessible.   I get the below notices.

 br /
 bNotice/b:  Undefined variable: _SESSION in 
 b/path/twittertest-oauth2.php/b on line b21/bbr /
 br /
 bNotice/b:  Undefined variable: _SESSION in 
 b/path/twittertest-oauth2.php/b on line b21/bbr /
 br /
 bNotice/b:  Undefined index:  oauth_token in 
 b/path/twitteroauth/twitteroauth.php/b on line b118/bbr /
 br /
 bNotice/b:  Undefined index:  oauth_token_secret in 
 b/path/twitteroauth/twitteroauth.php/b on line b118/bbr /
 array(1) {
   [ ]=
   string(0) 
 }


 Any advice for keeping hope alive?  :)

 Thanks again

 Paul G


 On Jul 23, 2010, at 1:13 PM, Abraham Williams wrote:

 This is quick and dirty and assumes that oauth_token and oauth_token_secret
 are set in a session before you are redirected to twitter.com to authorize
 the application.

 $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
 $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
 $access_token = $connection-getAccessToken($_REQUEST['oauth_verifier']);
 var_dump($access_token);

 Abraham
 -
 Abraham Williams | Hacker Advocate | http://abrah.am
 @abraham | http://projects.abrah.am | http://blog.abrah.am
 This email is: [ ] shareable [x] ask first [ ] private.





Re: [twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-22 Thread Taylor Singletary
Hi Paul G,

In addition to Paul's great recommendations here, there's another
shortcut you can use to more quickly implement the portions of OAuth
you need to continue functioning. We offer the ability to simply get
the access token for the user who owns your application, directly
through an interface on dev.twitter.com -- when viewing your
application detail page, you can select the link on the right-hand
sidebar called My Token and then use those values, hardcoded, in
your application. There's some implementation examples of this at
http://bit.ly/1token

Taylor

On Thu, Jul 22, 2010 at 12:04 PM, Paul cron...@gmail.com wrote:

 Hi Paul,

 1. Do I need to upgrade to OAuth?

 Twitter are killing off basic authentication on 16th August, so you'll
 need to upgrade.

 2. If I need to upgrade to OAuth, can it be done in such a way as to
 work without browser login and redirect requirements? (as per example)

 The Twitter OAuth tokens don't currently expire so you could do the
 auth once then store the tokens for later non-interactive use.

 3. If 2 is true, any tutorials that match that situation you can point
 me to?

 Don't know if you're tied to a current library but 
 http://github.com/jmathai/twitter-async
 does a good job of OAuth.

 Rough process:

 One off:

 1) Login to your company Twitter account.
 2) Settings - Connections - Click the link under Developers at
 bottom right.  Takes you to: http://twitter.com/apps
 3) Register your app.  You can get away with 127.0.0.1 as the callback
 URL if you're running a local webserver, but it's not so important if
 you're just doing this as a one off as you can specify callback URL at
 request time.

 You'll probably want:

 Type: Browser
 Access Type: Read  Write
 Use Twitter for login: No

 This will get you your consumer key  secret.

 4) Assuming use of twitter-async, here's some scrappy code that'll get
 you your tokens:

 ?php

 require_once twitter-async/EpiCurl.php;
 require_once twitter-async/EpiOAuth.php;
 require_once twitter-async/EpiTwitter.php;

 define( CONSUMER_KEY, X );
 define( CONSUMER_SECRET, X );

 $twitter = new EpiTwitter( CONSUMER_KEY, CONSUMER_SECRET );

 if( isset( $_GET[oauth_token] ) )
 {
        try
        {
                $twitter-setToken( $_GET[oauth_token] );
                $token = $twitter-
getAccessToken( array( oauth_verifier =
 $_GET[oauth_verifier] ) );
                var_dump( $token-oauth_token, $token-
oauth_token_secret );
        }
        catch( Exception $e )
        {
                var_dump( get_class( $e ) );
        }
 }
 else
        header( Location:  . $twitter-getAuthorizeUrl( null,
 array( oauth_callback = http://127.0.0.1/
 path_to_this_script.php ) ) );

 ?

 Obviously change the callback URL to point to wherever you host this
 script, and fill in your consumer key/secret.

 After you've authed the account, twitter will bring you back and the
 script will spit out your oauth_token and oauth_secret.


 So from now on if you want to tweet, you simply:

 $twitter = new EpiTwitter( CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN,
 OAUTH_TOKEN_SECRET );
 $twitter-post_statusesUpdate( array( status = Something exciting
 happened! ) );


 There's probably an easier way to get the tokens, but this worked well
 for me.

 Hope this helps,
 - Paul




Re: [twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-22 Thread Paul S Gutches



thanks for fast-tracking me on this!

I imagine I would have been at this several more days without this  
information.


Thank you, thank you...  and did I say thank you?  :)

Regards



On Jul 22, 2010, at 1:04 PM, Paul wrote:




One off:

1) Login to your company Twitter account.
2) Settings - Connections - Click the link under Developers at
bottom right.  Takes you to: http://twitter.com/apps
3) Register your app.  You can get away with 127.0.0.1 as the callback
URL if you're running a local webserver, but it's not so important if
you're just doing this as a one off as you can specify callback URL at
request time.






[twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-22 Thread Paul

Hi Paul,

 thanks for fast-tracking me on this!

You're welcome, glad to help :)

@Taylor: Very useful, thanks!

- Paul


[twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-22 Thread Paul

Hi Paul,

 Is there a way to retrieve the consumer keys for the other Twitter  
 account I own without registering an app?

Yep, if you use that script given previously, just login to the other
Twitter account instead (with the same consumer key/secret.  This will
give you a different pair of tokens for the second account.

Initialise as in tweeting example with the new token.  Basically what
you're doing is authorising the same app for both accounts.

- Paul



[twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-22 Thread Bess
Hi Taylor,

Can you explain more? How this is different than OAuth complete dance?
http://dev.twitter.com/pages/oauth_single_token

How do I use this single token hardcode method in mobile? iPhone
objective-c OAuth lib, Android java OAuth lib?

Thanks
Bess

On Jul 22, 4:53 pm, Paul cron...@gmail.com wrote:
 Hi Paul,

  Is there a way to retrieve the consumer keys for the other Twitter  
  account I own without registering an app?

 Yep, if you use that script given previously, just login to the other
 Twitter account instead (with the same consumer key/secret.  This will
 give you a different pair of tokens for the second account.

 Initialise as in tweeting example with the new token.  Basically what
 you're doing is authorising the same app for both accounts.

 - Paul


Re: [twitter-dev] Re: Twitter oAuth for PHP, some advice needed

2010-07-22 Thread Paul S Gutches



Paul,

If you are referring to the twitter-async example you posted, I have  
installed that and I'm working with it now.


I assume the first time through it's meant to take a detour through a  
Twitter authorization, then back to the same script in which  
oauth_token and secret is set... and dumped...


Looks like I'm not getting a proper authorize URL, and in fact the  
script dies at that call.  No output.   Maybe someone can eyeball  
what's going wrong.


Here's what the stack trace says, followed by the script

(the names and places have been changed to protect the innocent)

bFatal error/b:  Uncaught exception 'EpiOAuthException' in /path/ 
twitter-async/EpiOAuth.php:397

Stack trace:
#0 /path/twitter-async/EpiOAuth.php(367): EpiOAuthException::raise 
(Object(EpiCurlManager), false)
#1 /path/twitter-async/EpiOAuth.php(47): EpiOAuthResponse-gt;__get 
('oauth_token')
#2 /path/twittertest-oauth2.php(29): EpiOAuth-gt;getAuthorizeUrl 
(NULL, Array)

#3 {main}
  thrown in b/path/twitter-async/EpiOAuth.php/b on line b397/ 
bbr /


?php

require_once classes/twitter-async/EpiCurl.php;
require_once classes/twitter-async/EpiOAuth.php;
require_once classes/twitter-async/EpiTwitter.php;

define( CONSUMER_KEY, $MY_CONSUMER_KEY );  // actual key used
define( CONSUMER_SECRET, $MY_CONSUMER_SECRET );  // actual secret  
used


$twitter = new EpiTwitter( CONSUMER_KEY, CONSUMER_SECRET );

if( isset( $_GET[oauth_token] ) ){
try{
$twitter-setToken( $_GET[oauth_token] );
$token = $twitter-getAccessToken( array( oauth_verifier = $_GET 
[oauth_verifier] ) );

var_dump( $token-oauth_token, $token-oauth_token_secret );
}
catch( Exception $e )
{
var_dump( get_class( $e ) );
}
}else{
$location = $twitter-getAuthorizeUrl(null,array(oauth_callback = http://www.mydomain.tld/dir/twittertest-oauth2.php 
)); // same address as this script

header(Location: $location);
exit;
}
?




On Jul 22, 2010, at 5:53 PM, Paul wrote:


Hi Paul,


Is there a way to retrieve the consumer keys for the other Twitter
account I own without registering an app?


Yep, if you use that script given previously, just login to the other
Twitter account instead (with the same consumer key/secret.  This will
give you a different pair of tokens for the second account.

Initialise as in tweeting example with the new token.  Basically what
you're doing is authorising the same app for both accounts.

- Paul