我想在我的web應用程序中使用gdata + Oauth2導出/導入谷歌聯繫人。該應用程序在js和java服務器端有一個客戶端,通過REST API進行通信。 JS的側通過谷歌進行auathorization得到以下數據gdata oauth2授權NullPointerException:沒有驗證標題信息
{
state:"38c4ebb6-b763-4e98-969c-16a86221ec71",
access_token:"ya29.BwEGCaDeWTzGqIwewwlmWreAMZdgNNexN1efOVGDcyY0f-gzXUot51F-Tzy5BX39CwGpbrL3JGjQ",
token_type:"Bearer",
expires_in:"3600"
}
我想使用的access_token獲得下列方式
ContactsService myService = new ContactsService(APP_NAME);
myService.setHeader("Authorization", "Bearer " + accessToken);
return GoogleDataUtils.getContactList(getContactFeed(myService));
其中
private ContactFeed getContactFeed(ContactsService myService) throws ServiceException, IOException {
URL feedUrl = new URL(URL_FOR_FEED);
Query myQuery = new Query(feedUrl);
myQuery.setMaxResults(Integer.MAX_VALUE);
ContactFeed resultFeed = myService.getFeed(myQuery, ContactFeed.class);
return resultFeed;
}
但我接觸得到是
Exception in thread "main" java.lang.NullPointerException: No authentication header information
at com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96)
at com.google.gdata.util.AuthenticationException.<init>(AuthenticationException.java:67)
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:608)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:1077)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:676)
at com.google.gdata.client.Service.getFeed(Service.java:1034)
我已經找到了解決問題的SpreadsheetService
gdata-java-client + oauth2 + access_token secret
但它沒有爲我工作。
請你指點我做錯了什麼? 任何幫助將不勝感激
感謝
爲什麼JS正在執行身份驗證?如果您將Java作爲服務器端,則應遵循[使用OAuth2 for Web Apps](https://developers.google.com/accounts/docs/OAuth2WebServer)流程。無論如何,Java端的'accessToken'輸出是什麼? – 2015-01-27 10:13:22
JS端執行oauth,因爲它只是一個前端,所以我不可能在服務器上只提供REST API的oauth。據我所知,只要令牌傳輸得到保證,這是一個有效的解決方案 – lopushen 2015-02-03 23:44:33