J7mbo / twitter-api-php

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

Uncaught Exception: No URL set! in TwitterAPIExchange.php:275 #276

Open yudazdk opened 5 years ago

yudazdk commented 5 years ago

I wrote the following code and got this issue:

ini_set('display_errors', true);

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

/ Set access tokens here - see: https://dev.twitter.com/apps/ / $settings = array( 'consumer_key' => "", 'consumer_secret' => "", 'oauth_access_token' => "", 'oauth_access_token_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=J7mbo'; $requestMethod = 'GET';

$twitter = new TwitterAPIExchange($settings); echo $twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(); ?>

J7mbo commented 5 years ago

I just copied and pasted the code just before you edit it, and ran it on my machine, with the tokens you had, and got a result. Can you elaborate on what your error is?

yudazdk commented 5 years ago

I displayed the errors by ini_set('display_errors', true);

Before I did that I got the error: Error Code 32: Could not authenticate you

yudazdk commented 5 years ago

This is the code:

require_once('TwitterAPIExchange.php');

/ Set access tokens here - see: https://dev.twitter.com/apps/ / $settings = array( 'consumer_key' => "noV7y6jDK9eG68iE217UwgwdA", 'consumer_secret' => "7cQp5E9JZguNZ2PBMq62l36tsxuKild5LOyKYQG4K6k5gXchaR", 'oauth_access_token' => "14597778-MyxcqNfnlBvNM9mGQzf6yxzxdnEkm3mBFmJQbhwpu", 'oauth_access_token_secret' => "7Kx9VLglBRJrVnAOkll4LFYU9hXnIspybDuRBMLH7T0Qg" );

/ 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=J7mbo'; $requestMethod = 'GET';

$twitter = new TwitterAPIExchange($settings); echo $twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(); ?>

yudazdk commented 5 years ago

Could that be authentication with my tokens ?

yudazdk commented 5 years ago

@J7mbo Could you help me ? I run the code on xampp.

J7mbo commented 5 years ago

I just ran the code you pasted above and it works perfectly.

yudazdk commented 5 years ago

I run it on Xampp. What could be the problem ?

yudazdk commented 5 years ago

@J7mbo Did you run the code with the same tokens as mine ?

J7mbo commented 5 years ago

Yes. I copied the code from this message, changed nothing, and I get a response back.

I would suggest clearing any cache, restarting your web server, and make a change at the top like echo "HELLO WORLD"; just to make sure that you are editing the correct file being served by your webserver.

yudazdk commented 5 years ago

Do you mrun it on your local host ? Do you use Xampp ?

J7mbo commented 5 years ago

Nope, I just ran it on localhost by typing php script.php with your code in it and it worked perfectly. This is why I suggest that there is something else causing your problem.

You can disprove that your problem is a caching one by putting:

echo "hello world";

at the top of your php file and then refreshing your page and seeing if hello world is printed.

If it's not, then there's the problem you need to figure out. Have you done this?

yudazdk commented 5 years ago

I have. It prints hello world.

In twitter developer app configuration what should be the value of callback url ?