问题描述
我正在尝试检索Google用户的联系人列表.此getContacts()在AsyncTask的doInBackground()中调用.至此,我已经收到了令牌.我以以下codeLab示例为基础: https://codelabs. developers.google.com/codelabs/appauth-android-codelab/#0
I'm trying to retrieve a Google user's contacts list.This getContacts() is called in the doInBackground() of an AsyncTask.I have -at this point- already received a token.I based my self on this codeLab sample : https://codelabs.developers.google.com/codelabs/appauth-android-codelab/#0
我正在修改本教程的第10点,因此尝试获取用户的联系人列表而不是用户的个人信息(<起作用)
I'm modifying the point n°10 of this tutorial so trying to fetch user's contact list instead of the user's personal info ( < which is working)
private List<ContactEntry> getContacts() {
ContactsService contactsService = new ContactsService("MY_PRODUCT_NAME");
contactsService.setHeader("Authorization", "Bearer " + token);
try {
URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
Query myQuery = new Query(feedUrl);
ContactFeed resultFeed = contactsService.query(myQuery, ContactFeed.class);
List<ContactEntry> contactEntries = resultFeed.getEntries();
return contactEntries;
} catch (Exception e) {
}
return null;
}
我的问题是,我总是收到此消息的异常:
My problem is that I always get an Exception with this message :
java.lang.NullPointerException: No authentication header information
有帮助吗?预先感谢
推荐答案
您可以参考相关主题.尝试修改客户端库的用户代理商:
You may refer with this related thead. Try modifying the client library's useragent:
ContactsService service = new ContactsService(applicationName);
service.getRequestFactory().setHeader("User-Agent", applicationName);
也基于此帖子 ,service.setOAuth2Credentials()
不会像Google Sites,Google Drive等中的其他服务那样在内部刷新令牌.如果要构建Google凭据,只需在构建Google凭据后添加以下行:googleCredential.refreshToken();
.
Also based from this post, service.setOAuth2Credentials()
doesn't refresh token internally like the other services in Google Sites, Google Drive and etc. If you build Google Credential, just add this line after building the Google Credential: googleCredential.refreshToken();
.
这篇关于无法使用Google Contacts API& amp;获取帐户列表OAuth 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!