Getting this as an error while hitting the twitter api

php

#1

{“errors”:[{“code”:32,“message”:“Could not authenticate you.”}]}

For the search tweets

This authorization headers i am passing
Authorization: OAuth oauth_consumer_key=“Gxxxxxxx82”, oauth_nonce=“62fxxxxxxxxxxxx1d8e4”, oauth_signature=“HbKsnr7ZGQEMX9vf9%2BoIO5XlK%2FY%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1476252267”, oauth_token=“18xxxxxxxxxxAgVF38”, oauth_version=“1.0”

Someone please help


#2

What library are you using? how are you building up the OAuth signature? What endpoint and query are you using? Are you using app-only, or user authentication?


#3

I am using this method for creating the signature for the api call

$sigBase = “GET&” . rawurlencode($requestTokenUrl) . “&”
. rawurlencode(“oauth_consumer_key=” . rawurlencode($consumerKey)
. “&oauth_nonce=” . rawurlencode($nonce)
. “&oauth_signature_method=” . rawurlencode($oauthSignatureMethod)
. “&oauth_timestamp=” . $oauthTimestamp
. “&oauth_version=” . $oauthVersion);
$consumersec_new=“MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98”;
$sigKey = $consumerKey . “&”;
$oauthSig = base64_encode(hash_hmac(“sha1”, $sigBase, $sigKey, true));

Please let me know if I am doing it in wrong way


#4

Have you thought about using one of the existing PHP libraries that do this for you, rather than rolling your own? (also, please don’t post your consumer keys etc in forum posts, that makes them available to others to use)


#5

Thanks @andypiper now I have included the TwitterOAuth library its working now.