从Google Apps Profile API检索照片

时间:2013-04-04 04:42:27

标签: google-apps-script google-profiles-api

我正在尝试使用Google Apps配置文件API检索Google Apps配置文件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"};
}

参考:

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

2 个答案:

答案 0 :(得分:1)

您可以查看此库。它允许您将配置文件图片作为blob获取而没有任何问题: https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/profiles-services

答案 1 :(得分:1)

您可以尝试使用

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

授权。