coinbase-phpcoinbase-api

How do I get a Coinbase current user's info via API calls using OAuth2 and PHP?


I've set up a site that can successfully store access tokens and grab the account balance, per the example in the Coinbase PHP library.

I'm a little stuck now; It isn't obvious to me how to employ the various api calls available for Coinbase. I'm sure I can figure this out eventually, but I want to make sure I'm not ignoring some functionality that is already built into the Coinbase PHP library

My assumption is that I need PHP to make authenticated JSON requests to Coinbase. Is that code something I need to write from scratch, or am I missing an example in the PHP library?

For example, I want to display the authenticated user's name on my site after they authorize the app. I don't see a built-in function for that in the PHP Library, so I assumed I needed to use the https://coinbase.com/api/v1/users call.

Can someone point me to an example of how this is actually done?


Solution

  • Thanks to Robin at Coinbase support, I got an answer. Here's an example showing how to grab some user details via the Coinbase OAUTH2 API in PHP.

    In this example, these functions are added to coinbase-php/lib/Coinbase.php, inside the Coinbase class:

    class Coinbase
    {
    
    /*...Existing functions here*/
    
    /*New stuff...*/
    
    
    public function getUserID()
    {
      return $this->get("users", array())->users[0]->user->id;
    }
    public function getUserName()
    {
      return $this->get("users", array())->users[0]->user->name;
    }
    public function getUserEmail()
    {
      return $this->get("users", array())->users[0]->user->email;
    }
    public function getUserTimeZone()
    {
      return $this->get("users", array())->users[0]->user->time_zone;
    }
    public function getUserNativeCurrency()
    {
      return $this->get("users", array())->users[0]->user->native_currency;
    }
    

    Notes