Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtaining the activity id from a URL for Google+?

Tags:

google-plus

Suppose I have the URL for an activity (https://plus.google.com/u/0/113050383214450284645/posts/D6wBp4445Lb). I want to obtain the activity ID so that I can test the Google+ API using the APIs explorer. What is the quickest way to do this, preferably without having to write any code?

like image 339
Casebash Avatar asked Dec 14 '12 11:12

Casebash


1 Answers

The easiest way is to just use the API explorer to get post ids.

Grab the user ID from the url (113050383214450284645) then perform a search on it or activities.list.

Example queries for your URL:

  • Using the search API
  • Using the activities list API

The items in the activity feed all will have the IDs that you need.

 "items": [
  {
   "kind": "plus#activity",
   "etag": "\"vOizmBw459qRNcWY-IdfxxuCIbk/9EWWtEdBWwclTPqfqnRuN6-34Rg\"",
   "title": "Have you visited the World of Coke yet?  What was your favorite part?",
   "published": "2012-11-05T14:54:01.010Z",
   "updated": "2012-11-05T14:54:01.010Z",
   "id": "z134ctopapf0vlfec23ahjiykpj2zf0ay04",
   "url": "https://plus.google.com/113050383214450284645/posts/D6wBp4445Lb",
   "actor": {
    "id": "113050383214450284645",
    "displayName": "Coca-Cola",
    "url": "https://plus.google.com/113050383214450284645",
    "image": {
     "url":         "https://lh3.googleusercontent.com/-3o0qMaMvuwc/AAAAAAAAAAI/AAAAAAAAAng/X3xmoXJpksI/photo.jp    g?sz=50"
    }
   },

In this example, the post id is z134ctopapf0vlfec23ahjiykpj2zf0ay04.

If you want to be even more accurate, you can ensure you are retrieving the right post by searching for a specific matched url. The following code should give you a gist of how this is done in JavaScript:

for (var activity in activities){
  activity = activities[activity];
  if (activity['url'] == postUrl){
    targetActivity = activity;
    document.getElementById('result').value= 'ID is:\n' + activity.id;
    isFound = true;
  }
}

I have created a little demo that shows how this is done here: Demo: URL to ID

like image 179
class Avatar answered Oct 31 '22 17:10

class