OAuth gmail令牌代码TokenResponseException:我应该使用什么代码?

时间:2017-08-01 01:22:31

标签: java android oauth gmail

所以我正在构建一个应该发送自动电子邮件的应用程序,我有点迷失。我一直在做一些研究,我只是不知道我在做什么,所以我很难搞清楚细节。在一个页面上,我发现了一个看起来像我需要的方法但是使用的例子' *'而不是名为code的变量的实际值。这是我正在编写的包含变量的代码示例:

public static Gmail init() throws IOException{
    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();

    sClientSecrets = GoogleClientSecrets.load(jsonFactory, mClientSecretReader);
    Log.d(TAG, "Client Secrets: " + sClientSecrets);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            httpTransport,
            jsonFactory,
            sClientSecrets,
            Arrays.asList(mScope)
    ).setAccessType("online").setApprovalPrompt("auto").build();

    String code = "***"; // <-----how do i get code?
    GoogleTokenResponse response = flow.newTokenRequest(code)
            .setRedirectUri(GoogleOAuthConstants.OOB_REDIRECT_URI).execute();
    GoogleCredential credential = new GoogleCredential()
            .setFromTokenResponse(response);

    return new Gmail.Builder(httpTransport, jsonFactory, credential)
            .setApplicationName(APP_NAME).build();

}//end init()

我不明白我应该为这个变量使用什么。我觉得我应该知道但是......我不知道。请指出这个问题。提前谢谢。

0 个答案:

没有答案