abraham / twitteroauth

The most popular PHP library for use with the Twitter OAuth REST API.
https://twitteroauth.com
MIT License
4.29k stars 1.71k forks source link

Error : code (#220))Your credentials do not allow access to this resource #525

Closed RizwanSFDC closed 7 years ago

RizwanSFDC commented 7 years ago

Dear abraham, i used the your twitteroauth library.by using this iam getting token and token secret but while sending tweet it shows an error : [code] => 220 [message] => Your credentials do not allow access to this resource Please check this and correct me if am doing any wrong here.

TestTweet.php.

<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require_once("../twitteroauth/autoload.php");
require_once("../twitteroauth/callback.php");

use Abraham\TwitterOAuth\TwitterOAuth;

$twData = array(
    'consumer_key' => 'XXXXXX',
    'consumer_secret' => 'XXXX',
    'callback_url' => 'callback.php'
);

$tw = new TwitterOAuth($twData['consumer_key'], $twData['consumer_secret']);
$content = $tw->get("account/verify_credentials");

$request_token = $tw->oauth("oauth/request_token", array("oauth_callback" => $twData['callback']));

print_R($request_token);

$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

/* Build authorize URL and redirect user to Twitter. */
$url = $tw->url("oauth/authorize", array("oauth_token" => $token));

$statuses = $tw->get("search/tweets", ["q" => "twitterapi"]);
//print_r($statuses);

$statues = $tw->post("statuses/update", ["status" => "hello world"]);
if ($tw->getLastHttpCode() == 200) {
    echo "Tweet posted succesfully";
} else {
     echo "Handle error case";
}

print_r($statues);
exit;
header('Location: ' . $url);
exit;

Response :

Array ( [oauth_token] => FPNJHwAAAAAAyMzhAAABWQNBBfo [oauth_token_secret] => xOoU9Ywub4KljjbDy8WWcfEee612FvBZP [oauth_callback_confirmed] => true ) Handle error case

stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [code] => 220 [message] => Your credentials do not allow access to this resource. )

    )

)

abraham commented 7 years ago

It looks like you are not redirecting the user to twitter.com to authorize access and then you are not exchanging the request token for an access token.

Make sure you are following the full sign in with twitter flow as described through https://twitteroauth.com/redirect.php and the following pages.

RizwanSFDC commented 7 years ago

Thank you so much :),now its working fine

andyhua commented 7 years ago

hello:) @abraham, how are you ! these days , i'm develop some api with your twitterauth , that cool. and i'm doing this https://twitteroauth.com/redirect.php content success, i got these oauth_token and oauth_token_secret and users could doing authorizing... but how can i get the twitter user info like name or uid ? , in actually i want the unique user id, i didn't found any doc or faqs from twitteroauth.com. and fond some problam like
private function pharRunning() { return false; //return class_exists('Phar') && !empty(\Phar::running(false)); } i'm fixed like that can be work.

$totken = $connection->oauth("oauth/access_token", ["oauth_verifier" => $oauth_verifier]); and this place thow a exception message was 此功能暫時無法使用

thanks. andyhua.

abraham commented 7 years ago

@andyhua open a new issue