256 Kilobytes

Answers in Server-Side | By August R. Garcia


534 views, 0 RAMs, and 1 comment

Tags: PHP, REST, PayPal API, cURL

Profile Photo - August R. GarciaAugust R. GarciaLARPing as a Sysadmi...Portland, ORSite Owner

PHP Function
function call_api($method, $url, $data = false) {

        $access_token = get_access_token();

        $ch       = curl_init();

        curl_setopt($ch, CURLOPT_URL            , $url);
        curl_setopt($ch, CURLOPT_HEADER         , false);
        curl_setopt($ch, CURLOPT_HTTPHEADER     , [
                'Content-Type: application/json',
                'Authorization: Bearer ' . $access_token
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER ,  false              );

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER ,  true               );
        curl_setopt($ch, CURLOPT_POSTFIELDS     ,  json_encode($data) );

        $result = curl_exec($ch);
        $err    = curl_error($ch);

        if ($err) { echo "cURL Error #:" . $err;          }
        else      { $json         = json_decode($result); }


        return $result;

If you get this error (Laravel):

  • Call to undefined function App\Http\Controllers\curl_init()

You can fix this by running this command to instal cURL:

  • sudo apt install php7.0-curl

Replace 7.0 with your version of PHP. You can check this with:

  • php -v

The function get_access_token() is from this thread:

Download more RAM. 🐏 ⨉ 0Posted by August R. Garcia 2 years ago 🕓 Posted at 12 April, 2019 21:28 PM PDT

Sir, I can do you a nice SEO.

Profile Photo - Some GuySome GuyBasic Subscriber

Also, this tool is fairly useful:

Download more RAM. 🐏 ⨉ 0Posted by Some Guy 2 years ago 🕓 Posted at 14 April, 2019 03:35 AM PDT

This is a debug account.

Post a New Comment

Do you like having a good time?

Register an Account

You can also login to an existing account or reset your password. All use of this site is subject to the terms of service and privacy policy.

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account

Answers— Read More

Find more related content below!