如何访问已登录的G+用户的公共配置文件(至少是userid)
How to access a logged in G+ user's public profile (at least userid)
我正在编写一个JS应用程序,需要使用登录的G+用户的公开头像。
使用Google+ API,我可以查询配置文件数据,如果我有一个用户id。
https://developers.google.com/apis-explorer/p/+/v1/plus.people.get
但是,我如何获得当前登录用户的userid ?
用户需要使用登录API将他们的Google+帐户连接到您的应用程序。
见:https://developers.google.com/+/web/signin/
一旦用户登录,你可以使用userId 'me'获取他们的数据:
<button class="g-signin"
data-scope="https://www.googleapis.com/auth/plus.login"
data-clientid="{ YOUR_CLIENT_ID }"
data-callback="onSignIn"
data-theme="dark"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-width="wide">
</button>
(function() {
window.onSignIn = function(authResult) {
if (authResult.access_token) {
console.log('success');
gapi.client.load('plus','v1', function(){
var request = gapi.client.plus.people.get({'userId' : 'me'});
request.execute(function(response) {
console.log('ID: ' + response.id);
console.log('Display Name: ' + response.displayName);
console.log('Image URL: ' + response.image.url);
console.log('Profile URL: ' + response.url);
});
});
} else if (authResult.error) {
console.log('There was an error: ' + authResult.error);
}
};
var po = document.createElement('script'); po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
见:https://developers.google.com/+/web/signin/添加按钮# step_5_handling_the_sign-in
下面是工作示例:http://jsfiddle.net/imcg/3UU7E/
相关文章:
- 使用javascript配置文件作为handlebas博客模板,但配置不是't工作正常
- 我可以访问量角器配置文件中的参数吗
- 如何从配置文件中设置Angular值
- SoundCloud API-基于系统中的ID创建用户配置文件
- 先在Angular中加载配置文件,然后再加载其他文件
- 正在读取节点中的配置文件
- 检查蒸汽配置文件url是否有效
- 将配置文件文件夹移动到sdcardfirefoxmobile14.0
- 可能有一个javascript和php的配置文件
- 对CommonJS配置文件使用全局变量
- 未从Selenium网络驱动程序中的配置文件接收到正确的值
- 使用AddThis-config-data_ga_property向两个Google Analytics配置文件报告
- 如何使用浏览器“需要”配置文件,但不将此文件包含在捆绑包中
- Webdriver:用于动态禁用/启用JavaScript弹出窗口的Firefox配置文件
- 如何从 Webjar 解析多个 RequireJS 配置文件
- 通过oauth令牌passport.js访问用户配置文件
- mongodb用户配置文件添加输入时出现问题
- 如何使用ian:accounts-ui-botstrap-3根据Meteor中的用户输入设置配置文件字段值
- 带有所有用户操作的业务逻辑的Javascript配置文件
- 如何访问已登录的G+用户的公共配置文件(至少是userid)