Javascript 否';访问控制允许原点';请求的资源上存在标头。(谷歌联系人api)

Javascript 否';访问控制允许原点';请求的资源上存在标头。(谷歌联系人api),javascript,google-contacts-api,Javascript,Google Contacts Api,我正在尝试获取谷歌联系人的照片。从中可以看出: https://www.google.com/m8/feeds/photos/media/{userEmail}/{contactId} 我的代码: `$.get("https://www.google.com/m8/feeds/photos/media/default/54b8abe0f52ad02?access_token=" + authorizationResult.access_token + "&v=3.0",

我正在尝试获取谷歌联系人的照片。从中可以看出:

https://www.google.com/m8/feeds/photos/media/{userEmail}/{contactId}

我的代码:

`$.get("https://www.google.com/m8/feeds/photos/media/default/54b8abe0f52ad02?access_token=" + authorizationResult.access_token + "&v=3.0",
        function(response){
          //process the response here
          console.log(response);
        }
      );`
它给了我这个错误:

请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许对源“”进行访问。

但这似乎效果不错

`$.get("https://www.google.com/m8/feeds/contacts/default/full?alt=json&access_token=" + authorizationResult.access_token + "&max-results=500&v=3.0",
        function(response){
          //process the response here
          console.log(response);
        }
      );`
编辑: 完整js脚本:

`


var clientId='我的客户id';
var apiKey='api key';
var作用域https://www.googleapis.com/auth/contacts.readonly';
$(文档).on(“单击“,”.googleContactsButton”,函数(){
gapi.client.setApiKey(apiKey);
设置超时(授权);
});
函数authorize(){
gapi.auth.authorize({client_id:clientId,scope:scopes,immediate:false},handleAuthorization);
}
功能手动授权(授权结果){
if(authorizationResult&!authorizationResult.error){
$.get(”https://www.google.com/m8/feeds/photos/media/default/54b8abe0f52ad02?access_token=“+authorizationResult.access_token+”&v=3.0”,
功能(响应){
//在这里处理响应
控制台日志(响应);
}
);
}
}

`

我这样做得到了图片:(在图像url前面加上代理url)


您是否在代码中的任何位置创建代理..?我已经添加了完整的脚本。
<script type="text/javascript">
  var clientId = 'my client id';
  var apiKey = 'api key';
  var scopes = 'https://www.googleapis.com/auth/contacts.readonly';
  $(document).on("click",".googleContactsButton", function(){
    gapi.client.setApiKey(apiKey);
    window.setTimeout(authorize);
  });
  function authorize() {
    gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthorization);
  }
  function handleAuthorization(authorizationResult) {
    if (authorizationResult && !authorizationResult.error) {
      $.get("https://www.google.com/m8/feeds/photos/media/default/54b8abe0f52ad02?access_token=" + authorizationResult.access_token + "&v=3.0",
        function(response){
          //process the response here
          console.log(response);
        }
      );
    }
  }
</script>
`  function handleAuthorization(authorizationResult) {
    if (authorizationResult && !authorizationResult.error) {
      console.log(authorizationResult);
      var accessToken = authorizationResult.access_token;
      $.get("https://www.google.com/m8/feeds/contacts/default/thin?alt=json&access_token=" + accessToken + "&max-results=500&v=3.0",
        function(response){
          //process the response here
          console.log(response);
          let photoUrl = response.feed.entry[2].link[0].href + "&access_token=" + accessToken;
          let proxy = 'https://cors.now.sh/';
          let finalPhotoUrl = proxy + photoUrl;
          document.getElementById('photo').src = finalPhotoUrl;
        }
      );
    }
  }`