PHP Classes

getting oauth_client class to work with Stocktwits

Recommend this page to a friend!

      PHP OAuth Library  >  All threads  >  getting oauth_client class to work...  >  (Un) Subscribe thread alerts  
Subject:getting oauth_client class to work...
Summary:doesn't work
Messages:15
Author:Dirk Vandycke
Date:2013-02-10 03:12:40
Update:2013-03-02 10:35:34
 
  1 - 10   11 - 15  

  1. getting oauth_client class to work...   Reply   Report abuse  
Picture of Dirk Vandycke Dirk Vandycke - 2013-02-10 03:12:40
Hello Manuel,

First of all, thank you very much for sharing this class. It seems great. Got it up and running for twitter in a whim.

However I'm now trying to get it to work with Stocktwits(.com) and can't seem to get it working.

Here's what I did. I added a case in oauth_client (to be able to share it with this community if it worked):

case 'StockTwits':
$this->oauth_version = '2.0';
$this->request_token_url = '';
$this->dialog_url = 'https://api.stocktwits.com/api/2/oauth/authorize?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}&response_type=code&state={STATE}';//{RESPONSE_TYPE}

$this->append_state_to_redirect_uri = '';
$this->access_token_url = 'https://api.stocktwits.com/api/2/oauth/token';
$this->authorization_header = true;
$this->url_parameters = false;
break;

according to their documentation:
stocktwits.com/developers/docs/auth ...

then I made a copy of login_with_twitter.php and renamed it to login_with_stocktwits.php, and changed it like this:

$client = new oauth_client_class;
$client->debug = 1;
$client->server = 'StockTwits';
$client->response_type = 'code';
$client->scope = 'read,watch_lists,publish_messages,publish_watch_lists,direct_messages,follow_users,follow_stocks';
$client->redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].
dirname(strtok($_SERVER['REQUEST_URI'],'?')).'/login_with_stocktwits.php';

$client->client_id = '079aba316a36d678'; $application_line = __LINE__;
$client->client_secret = 'my secret';

But all I get is a response code 400. This is the resulting url:

api.stocktwits.com/api/2/oauth/auth ...

Any idea of what I'm doing wrong.
I'm no expert on this subject and just broke my head over it for the last few hours. So I'm kinda depleted of things to try.
I can give yu my secret as well (as it's just a test account I made on stocktwits).

If I/we get this working, this could be merged with your class for anyone else to benefit (as there doesn't seem to be much support for Stocktwits on oauth clients as it seems). I know the guys at stocktwits, so they could then add your class to http://stocktwits.com/developers/docs/libraries

Kind regards and thank you for considering helping me out.
Dirk

  2. Re: getting oauth_client class to work...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2013-02-11 06:05:07 - In reply to message 1 from Dirk Vandycke
I tried it myself and it works.

Are you sure the error 400 is not coming for a subsequent call to the API?

You may want to set the debug_http and debug variables to true so you can see the HTTP dialog.

  3. Re: getting oauth_client class to work...   Reply   Report abuse  
Picture of Dirk Vandycke Dirk Vandycke - 2013-02-11 09:09:26 - In reply to message 2 from Manuel Lemos
I got it to work a bit more
But not completely

It seems that my login_with_stocktwits.php now gets called a second time with a url parameter named code.
But when I add

if ($_GET['code'])
{
print 'https://api.stocktwits.com/api/2/account/verify.json?access_token=' . $_GET['code'];//checking if url is right
$client = new oauth_client_class;
//$client->access_token = $code;
$client->Initialize();
$client->Process();
$client->CallAPI('https://api.stocktwits.com/api/2/account/verify.json?access_token=' . $_GET['code'], 'GET', array(), array(), $response);

print_r ($response);
exit(0);
}

I get a 401 response (it's as if I'm not authorized)
As a non-expert it also seems strange to me that I have to deal with it like this (to catch the roundtrip). As you don't do something like this in your examples for other API's.

  4. Re: getting oauth_client class to work...   Reply   Report abuse  
Picture of Dirk Vandycke Dirk Vandycke - 2013-02-12 00:03:46 - In reply to message 2 from Manuel Lemos
could you perhaps send me your code example?
thank you very much!

dirk @ monest . net

  5. Re: getting oauth_client class to work...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2013-02-12 00:40:35 - In reply to message 3 from Dirk Vandycke
That access_token parameter on the CallAPI URL is wrong.

The class implicitly passes the correct value when it sends the HTTP request. Just do not put that paremeter in the URL.

The class will take the access_token value via the OAuth protocol.

If you already have gone through the authorization process, the access_token value is stored in a class variable with that name.

Therefore you can save that value, maybe in database, so you can restore the variable value and can call the API without going through the authorization process again.

  6. Re: getting oauth_client class to work...   Reply   Report abuse  
Picture of Dirk Vandycke Dirk Vandycke - 2013-02-15 14:32:40 - In reply to message 5 from Manuel Lemos
I understand so much. But the code is in the original login php with an if checking for the code as a get parameter, and that does seem to work out (i get the code)

but at that moment I can't initialize the you class anymore to use the callAPI method. If I do the whole proces starts over. If I don't the callAPI always returns a 401.

Could you perhaps share your code example or can I send you my complete code files (they are basicilly just the stocktwits case I added in the class and the login php 4 twitter I copied and adjusted

I'm also available on skype (dve845 - belgium)

  7. Re: getting oauth_client class to work...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2013-02-16 00:29:43 - In reply to message 6 from Dirk Vandycke
It seems you are confusing the codes. That code you are using is a code that is necessary to redeem the real access token. That is why it is not working for you.

You are always recommended to call the API using the CallAPI function because it takes care of other details.

I did not change anything in the class different from what you did. Anyway I will upload a new version of the class and the StockTwits example in the next few days.

  8. Re: getting oauth_client class to work...   Reply   Report abuse  
Picture of Dirk Vandycke Dirk Vandycke - 2013-02-16 01:20:29 - In reply to message 7 from Manuel Lemos
great, thank you very much

that way, I will probably see what you mean right away

nothing left for me but congratulate you on a very nice class, clean code, very transparant, ... keep up the good work

looking forward to your example

  9. Re: getting oauth_client class to work...   Reply   Report abuse  
Picture of Dirk Vandycke Dirk Vandycke - 2013-02-19 21:52:13 - In reply to message 7 from Manuel Lemos
Hello Manuel,

Just a quick reminder to put your new version online.
Thank you very much.

Kind regards
Dirk

  10. Re: getting oauth_client class to work...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2013-02-20 12:55:17 - In reply to message 9 from Dirk Vandycke
Sorry for the delay. I needed more time to also add support to Eventful OAuth server that works in an unusual way.

Anyway, the new version with StockTwits support is available. Just let me know if you have difficulties.

 
  1 - 10   11 - 15