问题描述
它始终显示您请求的页面无效。
我如何使用谷歌联系人获取javascript联系人api
i有有效范围和客户ID
it always says The page you requested is invalid.how can i fetch the contacts with javascript using google contacts apii have valid scope and Client ID
google.load('gdata', '2.x');
debugger
google.setOnLoadCallback(function () {
if (window.location.hash == "") {
if (!checkLogin()) {
logMeIn();
} else {
var feedUrl = "https://www.google.com/m8/feeds/contacts/default/full";
query = new google.gdata.contacts.ContactQuery(feedUrl);
query.setMaxResults(5000);
myService = new google.gdata.contacts.ContactsService('exampleCo-exampleApp-1.0');
myService.getContactFeed(query, function (result) {
document.cookie = "g314-scope-0=";
window.opener.parseGmailContacts(result.feed.entry);
close();
}, function (e) {
alert(e.cause ? e.cause.statusText : e.message);
});
}
}
});
function logMeIn() {
scope = "https://www.google.com/m8/feeds";
var token = google.accounts.user.login(scope);
}
function logMeOut() {
google.accounts.user.logout();
}
function checkLogin() {
scope = "https://www.google.com/m8/feeds/";
var token = google.accounts.user.checkLogin(scope);
return token;
}
我认为
var token = google.accounts.user.checkLogin(scope);
return token;
令牌返回(这里为空值),我怎样才能得到该值获取联系人的令牌,PLZ帮助
推荐答案
我遇到了同样的问题,我先通过检索解决了这个问题访问令牌,然后直接调用API。这是因为javascript api(gapi)不支持检索谷歌联系人。
I ran into the same problem, I solved it by first retrieving an access token, and then call the API directly. This is because the javascript api (gapi) does not support retrieving google contacts.
由于这很麻烦,我在这里写了一篇关于它的博文:
Since it was quite the hassle, I wrote a blogpost about it here: https://labs.magnet.me/nerds/2015/05/11/importing-google-contacts-with-javascript.html
基本上这就是我解决它的方式:
Basically this is how I solved it:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
</head>
<body>
<script type="text/javascript">
var clientId = 'your Client ID';
var apiKey = 'Your API Code';
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/contacts/default/thin?alt=json&access_token=" + authorizationResult.access_token + "&max-results=500&v=3.0",
function(response){
//process the response here
console.log(response);
});
}
}
</script>
<script src="https://apis.google.com/js/client.js"></script>
<button class="googleContactsButton">Get my contacts</button>
</body>
</html>
这篇关于使用javascript获取gmail联系人Google Contacts API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!