I have a website..previously when I was uploading a new post in my blog..It was getting posted to twitter automatically. But since the new version of OAuth system..It no longer works...Can anybody help me to sort out what to change?
My code is :
'Twitter'=>array(
'enabled' => true, //set to false to shut off twitter integration
'username' => 'blogspott', //your twitter.com username
'password' => 'W3Sw9OpW6HvZYl', //your twitter.com pasword
'consumer_key' => 'TdQS15VHBdZNIrQ7RPqVQ',
'consumer_secret' => 'B2Xe5h3lHXVXUgoCAxgAIdJDTeBf6AywRoGiTwB7I',
'oauth_token' => '283508422-FkiIyZq2tpx1PQOyBLyWyomXY9OdMKxxSKGcg9d3',
'oauth_token_secret' => '548kxcZCvhytdRkJ405QeWONvMyXNEpSZszIMEYU4W4',
'tweet'=>'#%POST% for just %URL-TO-POST% %LINK%',
// Bit.ly / URL Shortening
// Within your Tweets, auto-append short URLs i.e., bit.ly/s8dJksm, to save on space.
// Sign up for an API account at http://bit.ly, and place the information
// for that account in the box below
'short_url'=>array(
'append_short_url'=>false,
'short_url_provider'=>'bit.ly', // current option: bit.ly only (default), more soon!
'bitly'=>array(
'login' => 'o_78ocugrkqtf',
'api_key' => 'R_734dbe3be47605c405f4e19ec35eb617'
),
)
),
I am using the right keys here..I've double checked it.
Twitter did not change its OAuth system recently. It is not concerned by the controversial Twitter API 1.1. So verify that you are doing it just like Twitter asks and that you do not use deprecated endpoints (Twitter removed some of them recently).
Related
I have a website that uses the Twitter API (verrsion 1.1) with PHP and Zend framework 1 for validating the user name that is entered into a text input by a user of the application.
I created the app on Twitter and generated the Consumer Key (API Key), Consumer Secret (Secret API), Access Token and Access Token Secret.
General permissions: Read, write, and direct messages
Tokens permissions: Read and write
My PHP code for the authentication with Twitter is:
$config = array(
'version' => '1.1',
'signatureMethod' => 'HMAC-SHA1',
'callbackUrl' => 'http://example/main/twitter',
'siteUrl' => 'https://api.twitter.com/oauth',
'requestTokenUrl'=> 'https://api.twitter.com/oauth/request_token',
'accessTokenUrl' => 'https://api.twitter.com/oauth/access_token',
'authorizeUrl' => 'https://api.twitter.com/oauth/authorize',
'consumerKey' => self::$_consumeKey,
'consumerSecret' => self::$_consumeSecret
);
$session = new Zend_Session_Namespace('OAUTH_TWITTER');
$consumer = new Zend_Oauth_Consumer( $config );
$token = $consumer->getRequestToken();
$session->request_token = serialize($token);
$consumer->redirect();
When this code is executed, in the line:
$token = $consumer->getRequestToken();
returns the following error:
Could not retrieve a valid Token response from Token URL:
error code="215" Bad Authentication data.
I do not know what I did because previously was working perfectly. I researched for 2 weeks and still can not find the solution. I tried to create the application again, regenerate keys and tokens and change the time zone of my server to UTC but has not been solved.
If you need more information about me, please let me know.
I appreciate any information you can give me. Regards.
PD: sorry by my bad english
and thanx for reading, I'm trying to use Oauth with zend 2 by following this tutorial
but it seems Expired and all goes wrong with me, the last code I tried in my controller is:
$config = array(
// all these urls from details tab for my application
'siteUrl' => 'https://api.twitter.com/oauth/token',
'requesttokenUrl'=> 'https://api.twitter.com/oauth/request_token',
'accesstokenUrl' => 'https://api.twitter.com/oauth/access_token',
'authorizeUrl' => 'https://api.twitter.com/oauth/authorize',
'consumerKey' => 'API key from twitter api Keys tab',
'consumerSecret' => 'THE API secret from twitter api Keys tab'
);
// fetch a request token
$token = $consumer->getRequestToken();
// persist the token to storage
$_SESSION['TWITTER_REQUEST_TOKEN'] = serialize($token);
// redirect the user
$consumer->redirect(array('oauth_token' => urlencode(serialize($token))));
and this leads me to this page:
I don't know If this code is right and why I get this result.
is there any tutorial to lead me to do it right, or can any one help me with this?
any idea is appreciated, Thanx in advance.
I'm writing a library to connect to Twitter that uses Requests for PHP. I'm not sure, but I don't think that I'm building the OAuth correctly because I can't authenticate. I've double-checked it, and checked it against another existing library but still can't seem to get it right.
The code is here.
The idea is you instantiate the service, send it config parameters, and before it does the request, it generates the 'Authorization: OAuth xxx' header and adds it to said request.
$twitter = array(
'consumer_key' => '',
'consumer_secret' => '',
'access_token' => '',
'access_token_secret' => '',
'screen_name' => '_hassankhan',
'api_url' => 'https://api.twitter.com/1.1/'
);
$service = new OAuth1AService('Twitter', $twitter['api_url']);
$service->config($twitter);
$service->doGet(
'statuses/user_timeline.json',
array(
'screen_name' => '_hassankhan',
'include_entities' => 'true'
),
array(),
'raw'
);
print($service->getResult());
I would really recommend you to use one of the already made libraries like tmhOAuth which make it really easy to interact with the twitter api.
As for your problem, seems you don't sign your request correctly. At least I could not easily find out if you include all request parameters to create the signature.
The oauth_signature parameter contains a value which is generated by
running all of the other request parameters and two secret values
through a signing algorithm.
Creating the signature is described in this document: https://dev.twitter.com/docs/auth/creating-signature .
LinkedIn doesn't seem to like the idea of redirecting back to my test site.
This code directs me to the LinkedIn confirm page without any problems:
(This is pretty much a boilerplate example using Zend's OAuth)
$options = array(
'version' => '1.0',
'callbackUrl' => 'http://dev.local/',
'requestTokenUrl' => 'https://api.linkedin.com/uas/oauth/requestToken',
'userAuthorizationUrl' => 'https://api.linkedin.com/uas/oauth/authorize',
'accessTokenUrl' => 'https://api.linkedin.com/uas/oauth/accessToken',
'consumerKey' => [api],
'consumerSecret' => [secret]
);
$consumer = new Zend_Oauth_Consumer( $options );
// Start Requesting a LinkedIn Request Token
$token = $consumer->getRequestToken ();
// Store the LinkedIn Request Token
$_SESSION ['REQUEST_TOKEN'] = serialize ( $token );
// Redirect the Web User to LinkedIn Authentication Page
$consumer->redirect ();
However if my callback is http://dev.local/ it does not redirect, but if I specify a valid domain (like http://www.google.com) it redirects with no problem.
This behaviour happened recently (it was working fine until about a month ago). This is obviously a serious pain since I need to deploy code to be able to test anything.
Is this a problem people have experienced and has anyone found a way to get around?
it seems this is because LinkedIn changed their API, specifically how the api interacts with Oauth:
On the technical side, we've borrowed the OAuth 2.0 concept of the
"scope" parameter and incorporated it into our OAuth 1.0a and JS
Authentication flows.
Seems other apps, plugins and libraries are experiencing some difficulty with this as well.
Disclaimer,
Please pardon grammatical syntax.
I'm using the simple linkedin php library that is offered on the linkedin's site. I have followed their instructions and have successfully collected the users oauth-token and oauth-secret. Those 2 pieces of information have been stored in a database. I would like to know how make an offline oauth call, but im having trouble finding more information on the oath-verifier. This is the code that i have so far.
include('../../php/linkedin/linkedin_3.2.0.class.php');
include '../../php/global.settings.php';
$API_CONFIG = array(
'appKey' => LINKEDIN_APP_KEY,
'appSecret' => LINKEDIN_APP_SECRET,
'callbackUrl' => NULL
);
$linkedin = new LinkedIn($API_CONFIG);
$linkedin->request_token = "4e1e5ede-1de4-4eba-ba33-d3d37cbe67ff -FAKE";
$linkedin->access_token = "82b2c333-1075-441b-a51f-657196bf507w -FAKE";
$search_response = $linkedin->search("?company-name=facebook&count=10");
var_dump($search_response);
Temporarily I'm inserting the keys their on my own trying to bottleneck the behavior. Again, the authentication was successful, but my attempt to make a call to the users profile when the user is offline is a failure. I believe it is because im missing the oauth-verifier, but i don't believe that the oauth-verifier is necessary to make an offline call.The code pretty much breaks without any errors (if that is possible). I Have not tempered with the linkedin library nor there are any errors in the global.settings.php.
If you have already stored the user's access token then all you need to do is feed the access token in to the library and make your calls. From the demo file, something along the lines of:
$API_CONFIG = array(
'appKey' => LINKEDIN_APP_KEY,
'appSecret' => LINKEDIN_APP_SECRET,
'callbackUrl' => NULL
);
$linkedin = new LinkedIn($API_CONFIG);
$linkedin->setToken(array(
'oauth_token' => $token,
'oauth_token_secret' => $secret
));
$search_response = $linkedin->search("?company-name=facebook&count=10");
var_dump($search_response);