2016-09-08 10 views
0

これで、私は、Javaの知識をすべて知っています。つまり、保存と読み込みを除いてすべての機能を備えたアプリケーションがあります。JavaでのGoogleスプレッドシートからの読解

Googleスプレッドシートから保存して読み込みたいとします。

Google APIのドキュメントを参照して、プロジェクトにAPIをインストールしました。私が見た例もかなりコピーされています。 (What is an example of using OAuth 2.0 and Google Spreadsheet API with Java?

私は次のステップが何であるか知りたいです。今私はリダイレクトする必要があります(それは、デスクトップアプリケーション、ウェブアプリではない)、どこにリダイレクトするかわからないので、私はgoogle.comに追加されたコードを使用する方法を理解していない。

はい、私はいくつかの助けをいただければと思い、私はちょうどコピーして貼り付けてるように見え、これは承知しているが、実際にこれがそう作業プログラムのための唯一のハードルである:/

ありがとう!

package com.thepanthurr.security; 

import com.google.api.client.auth.oauth2.Credential; 
import com.google.api.client.googleapis.auth.oauth2.*; 
import com.google.api.client.http.HttpTransport; 
import com.google.api.client.http.javanet.NetHttpTransport; 
import com.google.api.client.json.jackson2.JacksonFactory; 

import java.awt.*; 
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.net.URISyntaxException; 
import java.net.URL; 
import java.util.Arrays; 
import java.util.List; 

public class InputOutput { 
    public static final String USERNAME = "Redacted.apps.googleusercontent.com"; 
    public static final String PASSWORD = "Redacted"; 
    public static final String SHEETURL = "https://www.google.com/"; 

    private static final List<String> SCOPES = Arrays.asList("https://www.googleapis.com/auth/spreadsheets"); 

    public static void read() throws IOException, URISyntaxException { 
     Credential credential = getCredentials(); 
     System.out.println(credential.toString()); 
    } 

    public static Credential getCredentials() throws IOException, URISyntaxException { 
     HttpTransport transport = new NetHttpTransport(); 
     JacksonFactory jsonFactory = new JacksonFactory(); 

     String authorizationUrl = 
       new GoogleAuthorizationCodeRequestUrl(USERNAME, SHEETURL, SCOPES).build(); 

     Desktop.getDesktop().browse(new URL(authorizationUrl).toURI()); 

     BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 
     String code = in.readLine(); //NO CLUE WHAT TO PUT HERE 

     GoogleTokenResponse response = 
       new GoogleAuthorizationCodeTokenRequest(transport, jsonFactory, USERNAME, PASSWORD, 
         code, SHEETURL).execute(); 

     return new GoogleCredential.Builder().setClientSecrets(USERNAME, PASSWORD) 
       .setJsonFactory(jsonFactory).setTransport(transport).build() 
       .setAccessToken(response.getAccessToken()).setRefreshToken(response.getRefreshToken()); 
     //What do I do after I receive the credentials? 
    } 
} 
+0

何か助けを借りますか?(まだスローガン:S – thePanthurr

答えて

0

このtutorialに従うようにしてください。 Google Spreadsheetに必要なものがすべて含まれています。

関連する問題