Error Code 32 - Laravel

laravel

#1

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.


#2

Hi @nlangerdev. Error 32 means there was an issue with the authentication data for the request. I noticed the example you sent contains a Postman token. When you remove that, does it still give you error 32?

Hamza


#3

Hey Hamza!

Thanks for the response, I have since removed the postman authentication from the code and it’s still giving me an error 32 message.

The API seems to work fine within postman, it’s just as soon as I fetch it across into my laravel project that I start to get issues.


#4

Are you sure that you are generating your oauth_nonce, oauth_signature, and oauth_timestamp properly?

Unfortunately I’m not too familiar with Laravel, but we can still try to help you out here.


#5

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.