Jeremy
Jeremy

Reputation: 312

How to get one's own cover photo URL with the Google Plus API

I need some assistance with using the Google + API and really simply (unless you're me) getting the URL of my own cover photo. I've tried following along with the API documentation and some tutorials online, but I'm pretty lost and don't even know what language the GET needs to be in. In addition, I know basic Javascript and PHP so I may not be able to write the request that is needed.

Essentially this is a repeat question of 'Get Google Plus cover URL by user_id', but I would like a more in depth explanation.

My request is:

GET https://www.googleapis.com/plus/v1/people/%2BJeremyMalais?fields=cover%2FcoverPhoto%2Furl&key={YOUR_API_KEY}
X-JavaScript-User-Agent:  Google APIs Explorer

And I just need the url from the response:

{
 "cover": {
  "coverPhoto": {
   "url": "https://lh4.googleusercontent.com/etc.JPG"
  }
 }
}

I've turned on the Google+ API and have created an OAuth Client ID and a Public API Access Key (for browser applications).

What's next?

Upvotes: 1

Views: 770

Answers (1)

Christian Læirbag
Christian Læirbag

Reputation: 338

Here's what to do using PHP:

<?php
    $id = "YOUR_GOOGLE_PLUS_ID";
    $key = "YOUR_API_KEY";
    $output = "https://www.googleapis.com/plus/v1/people/" . $id . "?fields=cover%2FcoverPhoto%2Furl&key=" . $key;
    $json = json_decode(file_get_contents($output));
    if (!($json === true || $json === false || $json === null))
        echo $json->cover->coverPhoto->url;
?>

Upvotes: 2

Related Questions