Google plus 检索用户';google/gmail的公共图片
我正在使用gmail api编写一个基于电子邮件的应用程序,我需要检索来自谷歌的电子邮件地址的用户公共图像。 我见过其他应用程序这样做,但我似乎无法可靠地获取这些数据 更多信息:Google plus 检索用户';google/gmail的公共图片,google-plus,gmail-api,Google Plus,Gmail Api,我正在使用gmail api编写一个基于电子邮件的应用程序,我需要检索来自谷歌的电子邮件地址的用户公共图像。 我见过其他应用程序这样做,但我似乎无法可靠地获取这些数据 更多信息: 我正在使用oauth2来登录用户-在那里请求任何类型的权限都没有问题 我曾尝试使用google+api检索图像,但它需要一个用户ID,我不知道如何获取电子邮件地址的用户ID(gmail api没有给出,阿飞) 我尝试过使用contacts API,但它只提供用户联系人的图像,而电子邮件客户端也可以显示其他用户的图像
- 我正在使用oauth2来登录用户-在那里请求任何类型的权限都没有问题
- 我曾尝试使用google+api检索图像,但它需要一个用户ID,我不知道如何获取电子邮件地址的用户ID(gmail api没有给出,阿飞)
- 我尝试过使用contacts API,但它只提供用户联系人的图像,而电子邮件客户端也可以显示其他用户的图像
我知道如果我有其他用户的用户ID,我可以从google plus接收所需的图像。但是,我找不到一种基于电子邮件地址获取用户ID的方法。Google+是正确的方法。这实际上与Gmail API无关。您不需要用户的userid,只需要具有适当作用域的有效访问令牌
https://www.googleapis.com/plus/v1/people/me?access_token=YOUR_ACCESS_TOKEN_HERE
除非有错误/无效令牌/etc,否则将以JSON的形式返回一组关于用户的信息。此数据中包含用户配置文件映像的URI
编辑:
要根据电子邮件地址获取用户的配置文件图片,请首先搜索该用户
https://www.google.com/m8/feeds/contacts/default/thin?q=EMAIL_ADDRESS_HERE
然后,您可以从返回的JSON中检索该用户的正确用户ID,并使用它获取配置文件图像。您可以使用google app profile API 下面是访问配置文件pic的示例代码
function getProfilePic(userName){
userName = 'yourusername@myDomain.com';
var scope = 'https://www.google.com/m8/feeds/';
var fetchArgs = googleOAuth_('Profile', scope);
fetchArgs.method = 'GET';
var domain = UserManager.getDomain();
var url = 'https://www.google.com/m8/feeds/photos/profile/'+domain+'/'+userName+'?v=3';
var rawData = UrlFetchApp.fetch(url, fetchArgs).getContentText();
//here you get data into rawData variable
}
//google oAuth
function googleOAuth_(name,scope) {
var oAuthConfig = UrlFetchApp.addOAuthService(name);
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey("anonymous");
oAuthConfig.setConsumerSecret("anonymous");
return {oAuthServiceName:name, oAuthUseToken:"always"};
}
您可以获得更多信息非常容易
http://picasaweb.google.com/data/entry/api/user/?alt=json
只是有点小问题
你只能从你的Google+个人资料中获取图片,而不能直接从你的gmail中获取
更新:
此API已被弃用,将于2019年1月被拒绝。尽快迁移到Google照片库API,以避免应用程序中断。
更多信息回答这个问题可能太迟了,但我发现最好的方法是先使用 ?alt=json 从JSON响应中,您将获得author部分,其中 uri:$t:https:picasaweb.google.com/0000000000000 现在,末尾的数字是用户ID,可用于使用此API检索用户配置文件 https:www.googleapis.com/plus/v1/people/userId
例如:https:www.googleapis.com/plus/v1/people/0000000000000从谷歌获取公共档案图像的简单javascript:
<html>
<body>
<script type="text/javascript">
function getPhoto() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myArr = JSON.parse(this.responseText);
try {
profilePic = myArr["feed"]["entry"][0]["media$group"]["media$thumbnail"][0]["url"];
document.getElementById("demo").innerHTML="<img src='" + profilePic + "' width='160px' height='160px'>"
}
catch(err) { }
}
}
xmlhttp.open("GET", "https://picasaweb.google.com/data/feed/api/user/<EMAIL>?kind=album&alt=json", true);
xmlhttp.send();
}
</script>
<div id="demo" onclick="javascript:getPhoto();">click here to load photo</div>
</body>
</html>
函数getPhoto(){
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
myArr=JSON.parse(this.responseText);
试试{
profilePic=myArr[“feed”][“entry”][0][“media$group”][“media$thumbnail”][0][“url”];
document.getElementById(“demo”).innerHTML=“”
}
捕获(错误){}
}
}
open(“GET”https://picasaweb.google.com/data/feed/api/user/?kind=album&alt=json“,对);
xmlhttp.send();
}
单击此处加载照片
更新:
此API已被弃用,将于2019年1月被拒绝。尽快迁移到Google照片库API,以避免应用程序中断。
信息
基于@jose920405-answer,我编写了这个免费的公共API服务,名为。这里有一些优点
- 不需要身份验证
- 它是完全免费和开源的
- 这是用科特林写的
- 您不需要编写一些用于映射响应的包装器
注意:此服务基于一个名为的独立库,可作为java项目(服务器或Android应用程序)中的渐变依赖项使用。如果您使用OAuth 2.0 API(例如使用passport)通过谷歌验证应用程序中的用户
您可以请求“profile”范围,它为您提供从displayName到用户配置文件照片“profile.photos[0]”的一系列信息。这几天来,我一直在努力解决这个问题,因为所有答案似乎都不起作用了。在未来的变化中,有效且看起来更健壮的是(它使用jQuery):
功能图像附加(GA){
user=GA.currentUser.get();
url=user.getBasicProfile().getImageUrl();
$('#缩略图').attr('src',url);
}
函数google_init(){
load('auth2',function(){
GA=gapi.auth2.init({
'客户id':'{您的谷歌客户id},
“获取基本配置文件”:true,
});
GA.then(函数(){
if(GA.isSignedIn.get()){
图像附加(GA)
}
否则{
GA.signIn().then(函数()){
图像附加(GA)
})}
})
});
}
您可以尝试以下方法
:
我希望这能奏效。这里是获取谷歌个人资料图片最有用的链接 1) 配置项目 2) 启用GOOGLE照片库API 设置上述步骤后,您将在验证后获得用户的配置文件图片链接作为响应 注意:启用谷歌照片库API后,您还可以获得另一个客户端ID和客户端密码,您可以使用
<img src="https://pikmail.herokuapp.com/eduardo.alejandro.pool.ake@gmail.com?size=50" alt="Profile Picture">
Picasso.with(context).load("https://pikmail.herokuapp.com/eduardo.alejandro.pool.ake@gmail.com?size=50").into(imageView);
<?php
$email = "YOUR_EMAIL_TO_FETCH";
$fetch_profile = "http://picasaweb.google.com/data/entry/api/user/".$email."?alt=json";
$jsonURL = file_get_contents($fetch_profile);
$json = json_decode($jsonURL);
$profile_img = get_object_vars($json->entry);
$profile_img = get_object_vars($profile_img['gphoto$thumbnail']);
$profile_img = $profile_img['$t'];
?>