私のプロジェクトは、私がherokuでホストしているJavaのスパークプロジェクトです。プロジェクトの一部では、Googleドライブからアプリケーションに特定のファイルをダウンロードする必要があります。アプリケーションをローカルで実行していたときにすべてをセットアップできましたが、アプリケーションをデプロイするとすぐに機能しなくなりました。これは、アプリケーションがローカルで実行されていたときに、Oauth2クライアントIDを他のタイプのものとして使用していたことに関係なく、アプリケーションをデプロイしたときに新しいタイプのWebアプリケーションを作成しました。私は私が手にダウンロードを開始しようとすると、Herokuの中にURLが以下のログに記録し、現在GoogleドライブOauth 2.0 for Java Webアプリケーション
public class AutoCalls {
/** Application name. */
private static final String APPLICATION_NAME = "calls-made";
private static final java.io.File DATA_STORE_DIR = new java.io.File(System.getProperty("target/classes/auth"), ".credentials/calls-made");
private static FileDataStoreFactory DATA_STORE_FACTORY;
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
private static HttpTransport HTTP_TRANSPORT;
private static final List<String> SCOPES = Arrays.asList(DriveScopes.DRIVE);
static {
try {
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
} catch (GeneralSecurityException | IOException t) {
System.exit(1);
}
}
public static void startDownload() throws IOException, ParseException {
Drive serv = getDriveService();
// drive stuff deleted
}
public static Credential authorize() throws IOException {
InputStream in = new FileInputStream("target/classes/auth/client_secret_*****************************************.apps.googleusercontent.com.json");
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(DATA_STORE_FACTORY)
.setAccessType("offline")
.build();
Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
System.out.println("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
return credential;
}
public static Drive getDriveService() throws IOException {
Credential credential = authorize();
return new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME)
.build();
}
}
:以下
は、認証と、ダウンロードコードの抜粋である2017-02-20T10:32:28.656820+00:00 app[web.1]: Please open the following address in your browser:
2017-02-20T10:32:28.656908+00:00 app[web.1]: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=************-vvdi7u6bmp1vc90sdidtnuiftdi1t49c.apps.googleusercontent.com&redirect_uri=http://localhost:48085/Callback&response_type=code&scope=https://www.googleapis.com/auth/drive
IブラウザでURLを開こうとするとエラーが表示されます。
Error: redirect_uri_mismatch
私はステップチューター任意のヘルプがarreiciatedされるようにJava Webアプリケーション上でGoogleドライブのコンテンツにアクセスする上でial。
私はアプリケーションをローカルで実行していたことが、それを意味するものではありませんか?クライアントIDはWebアプリケーションや他のもの(リダイレクトURLを持たないデスクトップアプリケーションの場合など)に使用できるため、私は尋ねます。クライアントIDは他のタイプのため、リダイレクトURLを受け付けませんでした。 – Chognificent
クライアントタイプを変更した理由を理解できません。確かに、あなたのアプリケーションは、実稼働中と同じようにテストする必要があります。標準的なアプローチでは、テスト環境と本番環境の両方のリダイレクトURLを持つ単一のクライアントIDを持つだけです。あなたが達成しようとしていることを誤解しているか、途中でOAuth /クライアントタイプを誤解しています。 – pinoyyid
私はクライアントタイプを変更しました。なぜなら私はリダイレクトURLを許可していないため、動作していなかった(他のもの)ためです。 – Chognificent