简体   繁体   中英

Twitter API 1.1 get direct messages “Your credentials do not allow access to this resource” error code 220

<?php  
    require_once('twitteroauth/twitteroauth.php');
    require_once('config.php');
    require_once('function.php');
    header("Content-Type: text/html; charset=utf-8"); 



    // Datadan kullanıcı çekiliyor
    $a = mysql_query("select * from users WHERE twid = 326960131");
    $i=0;
    while ($b = mysql_fetch_array($a)) { 
        $oauth_token[$i] = $b["oauth_token"]; 
        $oauth_secret[$i] = $b["oauth_secret"];
        $tid[$i]=$b["twid"];
        $connection[$i] = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token[$i], $oauth_secret[$i]);
        //Tüm bilgilerin kaynağı alınıyor
        $bilgi[$i] = $connection[$i]->get('account/verify_credentials');

        $i++;
    } 
    // -------------------------


    // Tweetpost döngüsü
    for ($i=0;$i<count($tid);$i++) {
        $screen_name = $bilgi[$i]->screen_name;
        $profilresmi = $bilgi[$i]->profile_image_url;
        $kullaniciid = $bilgi[$i]->id;
        $takipcisayisi = $bilgi[$i]->followers_count;


        $tweet = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access, $secret);

        $followers = $tweet->get('direct_messages', array('count' => '1'));

        print_r($followers);

    }
    flush();
?>

When I try to run this codes It says

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

I want to get direct messages of selected user. But it says like that. Can you help me?

There are two possible problems.

  1. Are you the authenticating user? Using the API you can only get your own messages.
  2. Check the permissions of your app on https://apps.twitter.com/ - did you request DM access, or read-only access?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM