Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter API returns NULL on XAMPP

Tags:

php

twitter

api

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));
like image 538
André Schmidt Avatar asked Sep 02 '13 13:09

André Schmidt


People also ask

How do I use the Twitter API?

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.

What is Twitter’s v2 API?

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.

What is the best Twitter API library for Python?

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)...

How to get Twitter API keys and authorization credentials?

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.


1 Answers

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!

like image 162
André Schmidt Avatar answered Nov 25 '22 15:11

André Schmidt