Question

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?

Was it helpful?

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

  • The "users" corresponds to the full API address call: "GET https://coinbase.com/api/v1/users".

  • The users API response is somewhat odd in that it appears to be designed to return multiple users via an array, even though it is defined as returning the "current user" info. That's why we have to add the "[0]" in the object for each of these functions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top