I am using like a tweet api in v2. It works fine in postman but giving me unauthorised 401 error.
Need help to find out what is the issue.
Are you using an access token and secret to authenticate calls or a Bearer token? You need to use the access token to make POST calls that like tweets
I am using oauth1.0.Its working fine to retweet a tweet but giving me error on like.
1 Like
Can you share a code example (with the tokens hidden)
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.twitter.com/2/users/id/likes',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"tweet_id": "tweeter id"
}',
CURLOPT_HTTPHEADER => array(
'Authorization: OAuth oauth_consumer_key="consumer key",oauth_token="token ",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1634872931",oauth_nonce="bXdMOQCDUy2",oauth_version="1.0",oauth_signature="outh signature"',
'Content-Type: application/json',
'Cookie: guest_id=v1%3A163392723975046164; personalization_id="v1_qPiVyU/oxA4TY/lTTPFY5A=="'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Chances are there is something wrong with the oAuth headers. You shouldn’t make raw curl calls, and use a library instead - there are multiple things that can go wrong with implementing this yourself
1 Like
It looks like the Authorization header is not valid, since the parameters need to be in alphabetical order. If you are using PHP, there are better options out there, such as TwitterOAuth, or elephant-bird.
1 Like