I'm trying to make a call to the Twitter API.
In short my problem is the same one as described here. Making my call I get NULL
on a var_dump()
of the result.
However
cURL works fine, I have included the newest version of the twitter-api-php script and all the tokens, keys and secrets are correct.
I'm working on a local XAMPP installation. Does this cause the problem? But it seems to work for other people. Is php configured wrong in my case? Or did I simply miss a semicolon (which I doubt because I don't get any errors)?
Here is my code:
ini_set('display_errors', true);
require_once('.\libs\TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => '############',
'oauth_access_token_secret' => '############',
'consumer_key' => '########',
'consumer_secret' => '###########'
);
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$requestMethod = "GET";
$getfield = '?screen_name=J7mbo';
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
var_dump(json_decode($response));
Using the Twitter API is very simple using RapidAPI. Just make the API call in your language of choice, get the data out of the API response, and use it however you’d like.
Twitter has recently released their v2 API and with it, a new developer tool called Projects. In order to use the v2 endpoints, developers have to create Projects, which at this point can contain a single app. Tweet caps and other endpoint restrictions apply at the project level.
Twitter for Python! The most popular PHP library for use with the Twitter OAuth REST API. Scrape the Twitter Frontend API without authentication. The most powerful and beautiful Twitter client available. Tweetinvi, an intuitive Twitter C# library for the REST and Stream API. It supports .NET, .NETCore, UAP (Xamarin)...
This will allow you to access the Twitter developer portal. 2. Head over to the Twitter Dev Site and Create a New Application Navigate to apps.twitter.com, sign in, and create a new application. After that, fill out all the app details and… …Voila! You now should be able to access all the required API Keys and authorization credentials.
Like Jimbo pointed out in the comments above, the solution can be found here
According to the article, the Windows PHP distribution doesn't come with an up-to-date bundle of the CA root certificates.
However, the bundle can be downloaded here. I put it under C:\xampp\php\cacert.pem
.
The second step is to add curl.cainfo=c:\xampp\php\cacert.pem
at the end of your php.ini file.
Change the path to your folder where you saved the .pem-file.
Restart Apache and now the problem should be solved!
Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With