I have an application which needs to get a feed of favourites from a user. If I set it up using oauthdamnit it seems to work fine:

This

$api = new OAuthDamnit(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET);

$raw = $api->get('https://api.twitter.com/1.1/favorites/list.json');
$response = json_decode($raw, true);
print_a ($response);

Returns this:

 Array
(
    [0] => Array
        (
            [created_at] => Mon Apr 14 19:32:26 +0000 2014
            [id] => 455790703126532096
            [id_str] => 455790703126532096
            [text] => Gmail put an update about Google+ straight ... etc

But I need to get them from another user – when I add ?screen_name=YSL for example:

This:

$api = new OAuthDamnit(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET);

$raw = $api->get('https://api.twitter.com/1.1/favorites/list.json?screen_name=YSL');
$response = json_decode($raw, true);
print_a ($response);

Returns this:

Array
(
    [errors] => Array
        (
            [0] => Array
                (
                    [message] => Could not authenticate you
                    [code] => 32
                )

        )

)

What am I doing wrong? https://dev.twitter.com/docs/api/1.1/get/favorites/list

有帮助吗?

解决方案

You are doing it wrong in $api->get.

If you want to pass parameter to url with GET request then pass it in function get as a SECOND parameter as array

$raw = $api->get('https://api.twitter.com/1.1/favorites/list.json',array('screen_name'=>'YSL'));

Here is the source code which says it self to pass $params in second parameter as an Array :

function get($url, $params = array()) {
     return $this->request('GET', $url, $params);
}

You can find it in oauthdamnit.php line no 39

其他提示

The API call only returns the favorites for the authenticated user and can't return data of arbitrary users, see the twitter API docs:

Returns the 20 most recent Tweets favorited by the authenticating or specified user.

Source: https://dev.twitter.com/docs/api/1.1/get/favorites/list

You have to obtain the correct username and password in order to make this API call work.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top