256 Kilobytes

Answers in Server-Side | By August R. Garcia

Published 6 months agoFri, 12 Apr 2019 21:28:54 -0700

204 views, 0 RAMs, and 1 comment

Tags: PHP, REST, PayPal API, cURL

Profile Photo - August R. Garcia August R. Garcia LARPing as a Sysadmi... Portland, OR
🗎 198 🗨 985 🐏 299
Site 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. 🐏 ⨉ 0 Posted by August R. Garcia 6 months ago 🕓 Posted at 12 April, 2019 21:28 PM PDT

Sir, I can do you a nice SEO.

Profile Photo - Some Guy Some Guy
🗎 3224 🗨 41 🐏 31

Also, this tool is fairly useful:

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

This is a patsy account used by the 256 Kilobytes staff to seed content. 

Post a New Comment

To leave a comment, login to your account or create an account.

Do you like having a good time?

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
You can also login to an existing account or recover your password. All use of this site is subject to terms outlined in the terms of service and privacy policy.