MunGell / Codeigniter-TwitterOAuth

Codeigniter and TwitterOauth library integration
76 stars 62 forks source link

Invalid Oauth token #3

Closed rajjagani021 closed 11 years ago

rajjagani021 commented 11 years ago

hey i can successfully authenticate by twitter but i get the OAuth token start with twitter user id just like 1095019810-Ue1ETxWf6ZFazHZHAioCXKU0DZXccccTNWvjeGP

so,how can i get valid access token and how can i post offline tweet using your library. I have try and i am not getting any error in twitter response but tweet is also not posted to user account

MunGell commented 11 years ago

Hi rajjagani,

Could you please post the error message you are receiving from Twitter? I just tried to post and it works fine for me.

Did you grant your application Read/Write access in admin interface (https://dev.twitter.com/apps/) ?

rajjagani021 commented 11 years ago

Yes, i have grant read/write access to my application. the application connect successfully with twitter and return to my website but when i try to store access token than access token include twitter user id along with that as i mention above..so i think this is invalid oauth token..

Now when i am separate the code of access token and used to post a tweet at that time tweet is not post to user account and i am not getting any error in response..

here is my code for post tweet

$this->connection = $this->twitteroauth->create($this->config->item('twitter_consumer_token'), $this->config->item('twitter_consumer_secret'),'Ue1ETxWf6ZFazHZHAioCXKU0DZXcvW1TNWvjeGP', $tweet_data->oauthTokenSecret);

$message=$tweet_data->offerTitle.' @'.$tweet_data->screenName.' - '.site_url('client/claim/index/'.$tweet_data->promId.'/'.$tweet_data->brandId.'/'.$tweet_data->offerId.'/tw'); $data=array( 'status' => $message );

$content = $this->connection->get('account/verify_credentials'); if(isset($content->error)) { echo $content->error; return false; } $result=$this->connection->post('statuses/update', $data); if(!isset($result->error)) { echo '

Your message is tweet on your twitter account.

'; echo 'Back to Main Page'; } else { echo $result->error; // Error, message hasn't been published //redirect(base_url('/')); }

MunGell commented 11 years ago

Well, from what I see here, you should use full access_token 1095019810-Ue1ETxWf6ZFazHZHAioCXKU0DZXccccTNWvjeGP, not only the second part of it.

Also, I hope you are propagating correct access_token_secret with $tweet_data->oauthTokenSecret, as I don't know what this variable contains.

If this does not help, please post here the error message you are receiving from Twitter.

rajjagani021 commented 11 years ago

Ok, as you said i tried with full access token but still i can't tweet to user account and $tweet_data->oauthTokenSecret contains the OAuth secret token of user.

the problem is i am not getting any error from twitter while posting but still i can't see my tweet on user account. here is the code what i write for tweet

$this->connection = $this->twitteroauth->create($this->config->item('twitter_consumer_token'), $this->config->item('twitter_consumer_secret'),$tweet_data->oauthToken, $tweet_data->oauthTokenSecret);

$message=$tweet_data->offerTitle.' @'.$tweet_data->screenName.' - '.site_url('client/claim/index/'.$tweet_data->promId.'/'.$tweet_data->brandId.'/'.$tweet_data->offerId.'/tw'); $data=array( 'status' => $message ); $result=$this->connection->post('statuses/update', $data); if(!isset($result->error)) { echo 'Your message is tweet on your twitter account.';
} else { echo $result->error; }

rajjagani021 commented 11 years ago

hey i have tried this library(Only for posting tweet) and its works... this is link https://github.com/elliothaughin/codeigniter-twitter

what i found they are using a method set_tokens($tokens) and after that the code is same while i am trying your code i think it is not set the access token properly so it is not posting tweet..

please take a look this library and tell me i am right or not because i am not sure about this. I am trying to solve this and one more thing the connection of app is not working on this library.

Please reply me as soon as possible

MunGell commented 11 years ago

This library you mentioned was updated last time 2 years ago and most probably will not work with present Twitter API.

Unfortunatelly, I cannot reproduce your problem on my installation - my sample controller works fine for auth/posting tweets. Thus, I only can guess what problem you are facing in your code while trying to post a message.

I can recommend you to try sample controller from the repository and if it works - debug your code and find the reason it is not working. Let me know if the sample code not working for you also.

rajjagani021 commented 11 years ago

hey can you please post your sample code here of controller so i can compare with that and figure out or you can mail me the code on rajjagani021@gmail.com. It would be very helpful. Thank you

MunGell commented 11 years ago

Sample code is in the repository: https://github.com/MunGell/Codeigniter-TwitterOAuth/blob/master/application/controllers/twitter.php

rajjagani021 commented 11 years ago

hey i have try the code as you have mention in above link but still i can't see my tweet on user account and the most difficult part is when i try to debug the code i am not getting any error in twitter response.

but when i try to call LastAPICall() method of your library i get this error

A PHP Error was encountered

Severity: Notice

Message: Undefined property: TwitterOAuth::$last_api_call

Filename: libraries/Twitteroauth.php

Line Number: 56

rajjagani021 commented 11 years ago

hey i fix my problem just one change for catch error in your library

in your library you use "$result->error" for catching errors but you have to used "$result->errors" and for printing errors

"echo $result->errors[0]->message"

so, the whole code is... if(isset($result->errors)) { echo $result->errors[0]->message; return false; }

and Thank you for all your help..

MunGell commented 11 years ago

Thank you for sharing this! I will update the sample controller accordingly.