2013-04-24 1 views
2

Google 스프레드 시트를 사용하려고하지만 이해할 수없는 문제가 있습니다.Google 스프레드 시트 getFeed 오류 및 이해

SpreadsheetService service = 
     new SpreadsheetService("MySpreadsheetIntegration-v1"); 

service.setOAuth2Credentials(credential); 
//service.setHeader("Authorization", "Bearer "+credential.getRefreshToken()); 

// TODO: Authorize the service object for a specific user (see other sections) 

// Define the URL to request. This should never change. 
URL SPREADSHEET_FEED_URL = new URL(
    "https://spreadsheets.google.com/feeds/spreadsheets/private/full"); 

// Make a request to the API and get all spreadsheets. 
SpreadsheetFeed feed = null; 
try { 
    feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class); 
} catch (ServiceException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 
List<SpreadsheetEntry> spreadsheets = feed.getEntries(); 

// Iterate through all of the spreadsheets returned 
for (SpreadsheetEntry spreadsheet : spreadsheets) { 
    // Print the title of this spreadsheet to the screen 
    System.out.println(spreadsheet.getTitle().getPlainText()); 
} 

난 할 노력하고있어하면 해당 변수 자격 증명 포인트 계정에서 스프레드 시트를 사용할 읽는 것입니다 : 나는 내 자신을 설명하기 전에

아래는 코드입니다. 나는 거기에 AccessToken과 RefreshToken을 둘 다 가지고있다.

나는 코드가 시도 캐치 다음과 같은 오류와 함께 캐치로 전환한다는 것입니다 실행하면 어떻게됩니까 :

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:998) 
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:645) 
at com.google.gdata.client.Service.getFeed(Service.java:1017) 
at DriveCommandLine.main(DriveCommandLine.java:69) 

당신은 내가 한 줄을 볼 수있는 내가, 서비스 변수의 기능을 연주했습니다 댓글을 달았습니다. 나는 RefreshToken 대신에 AccessToken을 시도해 보았지만 여전히 위에서 쓴 오류를 제공한다.

나는이 오류를 이해할 수 없다 : 그것은 어디서 비롯된 것인가? 왜 이런 일이 발생합니까? 어떻게 해결할 수 있습니까?

누군가 나를 도울 수 있다면 좋을 것입니다. 내가 가진다면 더 많은 정보를 가지고 돌아올거야.

+0

코드의 어딘가에'xoauth_requestor_id'를 사용하고 있습니까? –

+0

잘 모르겠습니다. 내가 어떻게 말할 수 있니? – FPJ

+0

다음 페이지를 참조하십시오. https://groups.google.com/forum/?fromgroups=#!topic/google-documents-list-api/BdzYdNz6I3Q –

답변

2

이 문제는 자랑스럽게하고있다 해결 :

좋아 내 실수 때문에 - 피드.

나는 OAth2를 사용하고 있으며 사용자에게 리디렉션하여 액세스 토큰을 검색 할 수 있도록 SCOPES가 첨부되어있어 앱에 어떤 권한을 부여 할 것인지를 의미합니다. 나는 피드를 참조하여 다음 마지막 두 누락되었습니다

private static final List<String> SCOPES = Arrays.asList(
    "https://www.googleapis.com/auth/drive.file", 
    "https://www.googleapis.com/auth/userinfo.email", 
    "https://www.googleapis.com/auth/userinfo.profile", 
    "https://docs.google.com/feeds", 
    "https://spreadsheets.google.com/feeds"); 

"의 OAuth 2.0 권한 부여 요청"에 https://developers.google.com/google-apps/spreadsheets/?hl=pt-BR에서 볼 수 있듯이.

credential.refreshToken(); 
srv.setOAuth2Credentials(credential); 
을 : 너무처럼 호출하기 전에 토큰을 갱신하는 것입니다 해결하기 위해

service.setOAuth2Credentials(credential); 

그래서 하나 개의 방법 :

지적하는 또 다른 것은 일부 사용자에 대한 몇 가지 문제가있을 것이다

누구든지이 게시물을 만나면 위의 정보가 유용하다고 생각합니다! :)

좋은 하루 되세요, 코더!