2013-02-13 1844 views
5

我在使用YouTube API并试图获取用户的YouTube链接。唯一显示的是Google+链接作为名为链接的字段。无论如何,从Google帐户信息中获取用户的Youtube信息?Google API:查找用户YouTube频道

Google Response在json响应中包含first_name,given_name和链接。

谢谢!

+0

如果您可以提供有关您正在进行的API调用的详细信息,您收到回复的示例以及您对“正在进行的操作”的解释(包括示例)用户的YouTube链接“。 – 2013-02-13 22:34:29

回答

1

我不知道这是否是你想要什么,但使用了Google+ API,您可以获取用户的URL,其中一人可以是用户的YouTube频道网址

更多信息: https://developers.google.com/+/api/latest/people/get

例如:

请求:

https://www.googleapis.com/plus/v1/people/117629885563933382879?key= {YOUR_API_KEY}

响应:

{ 
"kind": "plus#person", 
"etag": "\"l9gWq2lTiBDNZWBx8kpM7h7VNYs/as5084EFycaxtFP9IxDLvhbwZKM\"", 
"birthday": "0000-12-30", 
"gender": "male", 
"urls": [ 
    { 
    "value": "http://twitter.com/matiasmolinas", 
    "type": "other" 
    }, 
    { 
    "value": "http://gplus.to/matiasmolinas", 
    "type": "other" 
    }, 
    { 
    "value": "http://ar.linkedin.com/in/matiasmolinas", 
    "type": "other" 
    }, 
    { 
    "value": "https://www.facebook.com/matias.molinas", 
    "type": "other" 
    }, 
    { 
    "value": "http://www.youtube.com/user/matiasmolinasvideo", 
    "type": "other" 
    }, 
    { 
    "value": "http://stackoverflow.com/users/1427200/matias-molinas", 
    "type": "other" 
    }, 
    { 
    "value": "http://santafegtug.blogspot.com/", 
    "type": "other" 
    }, 
    { 
    "value": "http://fuse21.blogspot.com/", 
    "type": "other" 
    }, 
    { 
    "value": "http://lookthiscode.blogspot.com.ar/", 
    "type": "other" 
    }, 
    { 
    "value": "https://yt-topic-explorer.googlecode.com/git/dist/index.html", 
    "type": "other" 
    }, 
    { 
    "value": "http://santafegtug.appspot.com/", 
    "type": "other" 
    } 
], 
"objectType": "person", 
"id": "117629885563933382879", 
"displayName": "Matias Molinas", 
"name": { 
    "familyName": "Molinas", 
    "givenName": "Matias" 
}, 
"aboutMe": "Citas favoritas:<br /><br />Dentro de veinte años te sentirás más desilusionado por las cosas que no hiciste que por aquéllas que hiciste. Así que suelta las amarras. Navega fuera de la bahía segura. Atrapa los alisios en tus velas. Explora. Sueña. Descubre.<br />", 
"url": "https://plus.google.com/117629885563933382879", 
"image": { 
    "url": "https://lh3.googleusercontent.com/-AJKFDGod6us/AAAAAAAAAAI/AAAAAAAAD64/Olccnle-qH4/photo.jpg?sz=50" 
}, 
"organizations": [ 
    { 
    "name": "UNER", 
    "title": "Bioingenieria", 
    "type": "school", 
    "primary": false 
    }, 
    { 
    "name": "Software Consultant", 
    "title": "Software Consultant", 
    "type": "work", 
    "startDate": "2011", 
    "endDate": "2011", 
    "primary": true 
    }, 
    { 
    "name": "Software Santa Fe", 
    "type": "work", 
    "endDate": "2011", 
    "primary": false 
    } 
], 
"placesLived": [ 
    { 
    "value": "Santa Fe, Argentina", 
    "primary": true 
    } 
], 
"isPlusUser": true, 
"verified": false, 
"cover": { 
    "layout": "banner", 
    "coverPhoto": { 
    "url": "https://lh3.googleusercontent.com/-DjGbmNDlV3U/UNCgpGJu_WI/AAAAAAAAD7Q/7Uk2WidwxnI/w940-h428/gdesummit.png", 
    "height": 428, 
    "width": 940 
    }, 
    "coverInfo": { 
    "topImageOffset": -83, 
    "leftImageOffset": 0 
    } 
} 
} 
+0

这看起来正是我想要的。现在检查出来。 – 2013-02-18 17:38:17

+0

这是非常方便的:https://developers.google.com/oauthplayground/ 我从来没有得到任何方式工作,但认为我现在已经接近,我有完整的api终点列表:) – 2013-02-22 20:40:56

+6

希望你大家看到这个评论。如果上述请求位于链接的**其他**标签下方,则只会返回YouTube频道。如果它位于YouTube标签中,则不会显示在结果中。所以它只适用于少数几千个账户的渠道。是否有另外一种方法可以返回与给定G + ID关联的每个频道? – unknown 2014-10-07 09:21:46

0

按照谷歌的YouTube的API文档channels list,你可以得到一个包含所有,涉及到一个特定的谷歌用户的YouTube频道的JSON响应。

第一步

显然,你需要确保你使用OAuth 2.0登录到谷歌开发者API(确保你使用到YouTube范围:https://www.googleapis.com/auth/youtube)。这是因为您需要一个access_token,才能加载用户特定的数据。

第二步

channels list API可以找到经由通道:用户名,信道ID,等...的ID字符串然而必需的。相反,您可以将mine布尔参数设置为true,以便获取特定Google用户拥有的YouTube频道(您不必指定Google用户的ID,因为access_token可让YouTube知道哪个用户正试图加载数据)。

为了使用API​​,使用下面的URL发出请求(替换 'YOUR_ACCESS_TOKEN_HERE' 你access_token):

https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&mine=true&access_token=YOUR_ACCESS_TOKEN_HERE

这里是JSON回应,你会得到:

{ 
"kind": "youtube#channelListResponse", 
"etag": "xxxxxxxxxxxxxxxxxxxxxxxxxxx", 
"pageInfo": { 
    "totalResults": 1, 
    "resultsPerPage": 1 
}, 
"items": [ 
    { 
    "kind": "youtube#channel", 
    "etag": "xxxxxxxxxxxxxxxxxxxxxxxxxxx", 
    "id": "YOUTUBE_CHANNEL_ID", 
    "snippet": { 
    "title": "Daniel Sadjadian", 
    "description": "I’m Daniel Sadjadian - Car enthusiast, computer programmer & entrepreneur running my own business. I live life to the max and try my best to get the most out of each day. Every moment counts :)", 
    "customUrl": "danielsadjadian", 
    "publishedAt": "2013-11-09T19:47:41.000Z", 
    "thumbnails": { 
    "default": { 
     "url": "https://yt3.ggpht.com/-EF0LibpIsEY/AAAAAAAAAAI/AAAAAAAAAAA/n0mUHQnyfkc/s88-c-k-no-mo-rj-c0xffffff/photo.jpg" 
    }, 
    "medium": { 
     "url": "https://yt3.ggpht.com/-EF0LibpIsEY/AAAAAAAAAAI/AAAAAAAAAAA/n0mUHQnyfkc/s240-c-k-no-mo-rj-c0xffffff/photo.jpg" 
    }, 
    "high": { 
     "url": "https://yt3.ggpht.com/-EF0LibpIsEY/AAAAAAAAAAI/AAAAAAAAAAA/n0mUHQnyfkc/s240-c-k-no-mo-rj-c0xffffff/photo.jpg" 
    } 
    }, 
    "localized": { 
    "title": "Daniel Sadjadian", 
    "description": "I’m Daniel Sadjadian - Car enthusiast, computer programmer & entrepreneur running my own business. I live life to the max and try my best to get the most out of each day. Every moment counts :)" 
    }, 
    "country": "GB" 
    }, 
    "contentDetails": { 
    "relatedPlaylists": { 
    "likes": "LLXQYiggNxzVJ51ofKyG2ZUg", 
    "favorites": "FLXQYiggNxzVJ51ofKyG2ZUg", 
    "uploads": "UUXQYiggNxzVJ51ofKyG2ZUg", 
    "watchHistory": "HL", 
    "watchLater": "WL" 
    } 
    }, 
    "statistics": { 
    "viewCount": "30305", 
    "commentCount": "0", 
    "subscriberCount": "100", 
    "hiddenSubscriberCount": false, 
    "videoCount": "25" 
    } 
    } 
] 
} 

JSON响应包括有关用户'包括频道ID。然后,您可以使用频道ID(与其他YouTube API一起)加载频道视频/播放列表/活动/等...

相关问题