Hello, I am creating a controller within laravel to search for usernames or screen_name of a user depending on what a user has typed on the frontend.
I have tested this using Postman and it works perfectly returning results from twitter in a JSON format for me to use, however as soon as I export this code and use it inside of Laravel using PHP cURL I get the Error Code 32 as below:
{"errors":[{"code":32,"message":"Could not authenticate you."}]}
My code for the controller is as follows:
<?php
namespace PROJECTNAME\Http\Controllers;
use Illuminate\Http\Request;
class TwitterController extends Controller{
public function TwitterHandles($Search = null){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.twitter.com/1.1/users/search.json?q=".$Search,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
'Authorization: OAuth oauth_consumer_key="<redacted>",oauth_token="<redacted>",oauth_signature_method="HMAC-SHA1",oauth_timestamp="'.time().'",oauth_nonce="'<redacted>'",oauth_version="1.0",oauth_signature="'<redacted>'"',
'Postman-Token: c6080f4e-4e0d-4436-ab7f-c8b9ab6b72d5',
'cache-control: no-cache',
'oauth_consumer_key: <redacted>',
'oauth_signature: k6y40znWeQ0SDHyKRUkUEoM/rXg=',
'oauth_signature_method: HMAC-SHA1',
'oauth_token: <redacted>',
'oauth_version: 1.0'
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$response = json_decode($response, TRUE);
return response()->json($response);
}
}
Any help or advice on this would be amazing.