0

我正在尝试使用 Google Apps Profile API 检索 Google Apps Profile API 照片,但即使在授权请求后,它也会继续提示授权请求。这是我到目前为止尝试过的代码。

function getPhoto(userName){
  userName = 'user@myDomain.com'; //will be replaced by actual username
  var scope = 'https://www.google.com/m8/feeds/profiles';
  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();
  Logger.log(rawData);
}

//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"};
}

参考:

注意:我对我正在尝试的域具有超级管理员访问权限

4

2 回答 2

1

你可以看看这个图书馆。它使您可以毫无问题地将个人资料图片作为 blob 获取: https ://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/profiles-services

于 2013-04-14T15:22:02.213 回答
1

你可以试试

var scope = 'https://www.google.com/m8/feeds/';

授权。

于 2013-04-16T23:45:18.607 回答