Obtaining the activity id from a URL for Google+?

让人想犯罪 __ 提交于 2019-12-23 09:37:42

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/13878052/obtaining-the-activity-id-from-a-url-for-google

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!