J7mbo / twitter-api-php

The simplest PHP Wrapper for Twitter API v1.1 calls
MIT License
1.82k stars 800 forks source link

errors":[{"code":50,"message":"User not found."}]} #209

Closed hattaabdo closed 8 years ago

hattaabdo commented 8 years ago

hy i loved your api because its simple i did here all my infos $settings = array(

'oauth_access_token' => "847143656-kn2GflbzLvfprObqFwwYwXSn7I5vbbzjNY6nI1vT",
'oauth_access_token_secret' => "mm Secret )",
'consumer_key' => "6iBw0t8Fkpf4fTFaSLIMk5Hhg",
'consumer_secret' => "mm Secret )"

); this is all i modify in your api but still get that err:

{"errors":[{"code":50,"message":"User not found."}]}{"ids":[],"next_cursor":0,"next_cursor_str":"0","previous_cursor":0,"previous_cursor_str":"0"}

THANKS in advance

J7mbo commented 8 years ago

You've provided your $settings array, can you also provide the code you run to make the request, with the url in it etc?

hattaabdo commented 8 years ago

url :http://vielen.net/autotw/ i modified this also $url = 'https://api.twitter.com/1.1/followers/ids.json'; $getfield = '?screen_name=hatta28328506'; can y pls check my id if its correct from https://twitter.com/hatta28328506

hattaabdo commented 8 years ago

full page

<?php
ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');

/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
    'oauth_access_token' => "847143656-kn2GflbzLvfprObqFwwYwXSn7I5vbbzjNY6nI1vT",
    'oauth_access_token_secret' => " ",
    'consumer_key' => "6iBw0t8Fkpf4fTFaSLIMk5Hhg",
    'consumer_secret' => " "
);

/** URL for REST request, see: https://dev.twitter.com/docs/api/1.1/ **/
$url = 'https://api.twitter.com/1.1/blocks/create.json';
$requestMethod = 'POST';

/** POST fields required by the URL above. See relevant docs as above **/
$postfields = array(
    'screen_name' => 'usernameToBlock', 
    'skip_status' => '1'
);

/** Perform a POST request and echo the response **/
$twitter = new TwitterAPIExchange($settings);
echo $twitter->buildOauth($url, $requestMethod)
             ->setPostfields($postfields)
             ->performRequest();

/** Perform a GET request and echo the response **/
/** Note: Set the GET field BEFORE calling buildOauth(); **/
$url = 'https://api.twitter.com/1.1/followers/ids.json';
$getfield = '?screen_name=hatta28328506';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest();
J7mbo commented 8 years ago

Okay. So what are you trying to do? Because according to this, you're trying to make a POST request first, and then a GET request afterwards. The first POST request won't work, because you've got: 'screen_name' => 'usernameToBlock' and that doesn't exist.

You've got redundant code in there you're not even using.... Try this...

ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');

/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
    'oauth_access_token' => "847143656-kn2GflbzLvfprObqFwwYwXSn7I5vbbzjNY6nI1vT",
    'oauth_access_token_secret' => " ",
    'consumer_key' => "6iBw0t8Fkpf4fTFaSLIMk5Hhg",
    'consumer_secret' => " "
);

/** Perform a GET request and echo the response **/
/** Note: Set the GET field BEFORE calling buildOauth(); **/
$url = 'https://api.twitter.com/1.1/followers/ids.json';
$getfield = '?screen_name=hatta28328506';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest();
hattaabdo commented 8 years ago

err changed to {"ids":[],"next_cursor":0,"next_cursor_str":"0","previous_cursor":0,"previous_cursor_str":"0"} user not found disapeared )

J7mbo commented 8 years ago

That's perhaps because you're querying /followers/ to get a list of followers, but when you actually look at their profile, there are no followers for this user.

hattaabdo commented 8 years ago

ah y mean no one is follwing me?

hattaabdo commented 8 years ago

Big thanks hero ) i'll make some extra users & make them to follow me ) & i'll see

J7mbo commented 8 years ago

Here's your profile: link

It shows no followers.

Here's mine: link

See how mine has followers?

Closing the issue as there's nothing wrong in this particular example.

If you have any other problems, please feel free to start a new issue for that specific problem. Thanks.

hattaabdo commented 8 years ago

alright thanks ) you got +1 follower xD

silvanet commented 8 years ago

OK, thanks, I'm getting clearer on that file and its contents. I see what you were saying about redundant code. There are both the GET and POST methods in it. I cleaned up the code as per your example here above. I looked up the link required in the apaigee twitter console and tried to get data from the https://api.twitter.com/1.1/statuses/user_timeline.json. I don't see much help on the twitter api documentation on the syntax of a request with the parameters. I was expecting to see a graphic timeline, but the result was a huge amount of unformatted data.

How do I get the tweets to show up in graphic format?

J7mbo commented 8 years ago

@silvanet The data isn't unformatted, it's JSON which is definitely structured data ;) That'll allow you to loop around it, pull out what you want specifically etc. Twitter gives you the data and then it's up to you as a developer to place them in the format you want: either interpolating with CSS + HTML to make your own timeline or use the data for some other purpose.

silvanet commented 8 years ago

​I take it that this example from twitteroauth does just that because the timeline comes out in graphic format (but oddly in Chrome and not in Firefox where it comes out as a series of links), but the syntax does not work with your data pull. Can you tell me what I have to alter here? Again, twitter API 1.1 is not very clear on examples (maybe I can pull up the old version 1.0 site which I know had examples). I figure I have to do something with your line:

$getfield = '?screen_name=silvanet'; //I'm silvanet//

This code in twtteroauth gave me the format I wanted.

$tweets = $connection->get("statuses/user_timeline",["screen_name" => "silvanet" ,"count" => 20, "exclude_replies" => true]);

foreach ($tweets as $tweet) {

if ($tweet->favorite_count > 0) {

    $id = $tweet->id;

    echo $id." ".$url. "<br>";

    $embed = $connection->get("statuses/oembed", ["id" => $id]);

    echo $embed->html;

}

}​

On Thu, Sep 8, 2016 at 5:16 AM, James Mallison notifications@github.com wrote:

@silvanet https://github.com/silvanet The data isn't unformatted, it's JSON which is definitely structured data ;) That'll allow you to loop around it, pull out what you want specifically etc. Twitter gives you the data and then it's up to you as a developer to place them in the format you want: either interpolating with CSS + HTML to make your own timeline or use the data for some other purpose.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/J7mbo/twitter-api-php/issues/209#issuecomment-245540423, or mute the thread https://github.com/notifications/unsubscribe-auth/AG6JmqYLVhBfYZMsnOtPjz4tJZ_UqFYIks5qn9JSgaJpZM4JwT3Y .

silvanet commented 8 years ago

Thanks for your help. I figured it out. Once I viewed the jumbled mess in the page source it gave me enough format to be able to look through and find the different fields. Then using the foreach I just echoed items I was interested in. I think I can now figure it out better from here. By the way, thanks for putting some examples on your Wiki.

On Thu, Sep 8, 2016 at 9:53 AM, Ray Silva silvanet@gmail.com wrote:

​I take it that this example from twitteroauth does just that because the timeline comes out in graphic format (but oddly in Chrome and not in Firefox where it comes out as a series of links), but the syntax does not work with your data pull. Can you tell me what I have to alter here? Again, twitter API 1.1 is not very clear on examples (maybe I can pull up the old version 1.0 site which I know had examples). I figure I have to do something with your line:

$getfield = '?screen_name=silvanet'; //I'm silvanet//

This code in twtteroauth gave me the format I wanted.

$tweets = $connection->get("statuses/user_timeline",["screen_name" => "silvanet" ,"count" => 20, "exclude_replies" => true]);

foreach ($tweets as $tweet) {

if ($tweet->favorite_count > 0) {

    $id = $tweet->id;

    echo $id." ".$url. "<br>";

    $embed = $connection->get("statuses/oembed", ["id" => $id]);

    echo $embed->html;

}

}​

On Thu, Sep 8, 2016 at 5:16 AM, James Mallison notifications@github.com wrote:

@silvanet https://github.com/silvanet The data isn't unformatted, it's JSON which is definitely structured data ;) That'll allow you to loop around it, pull out what you want specifically etc. Twitter gives you the data and then it's up to you as a developer to place them in the format you want: either interpolating with CSS + HTML to make your own timeline or use the data for some other purpose.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/J7mbo/twitter-api-php/issues/209#issuecomment-245540423, or mute the thread https://github.com/notifications/unsubscribe-auth/AG6JmqYLVhBfYZMsnOtPjz4tJZ_UqFYIks5qn9JSgaJpZM4JwT3Y .

tajinder0071 commented 7 years ago

@J7mbo I used your code to get the data from twitter, just changed the values in settings array by getting from my developer account. No I am making the GET request same as your example, but getting the error '"code":50,"message":"User not found."'. Can you please help me on this.

J7mbo commented 7 years ago

Hi @tajinder0071 - can you open a new issue with your problem and the exact code you used and then we can look at it. Thanks.