我想使用谷歌的人api,但我面臨着很多困難。從api控制檯生成的json文件不包含clientSecret。我在哪裏可以得到它?所以我得到空授權代碼。任何人都可以幫助我解決這個問題嗎?在此先感謝Google People API在Android應用程序中的實現
public void setUp() throws IOException {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
// Go to the Google Developers Console, open your application's
// credentials page, and copy the client ID and client secret.
// Then paste them into the following code.
String clientId = "";
String clientSecret = "";
// Or your redirect URL for web based applications.
String redirectUrl = "urn:ietf:wg:oauth:2.0:oob";
String scope = "https://www.googleapis.com/auth/contacts.readonly";
// Step 1: Authorize -->
String authorizationUrl = new GoogleBrowserClientRequestUrl(clientId,
redirectUrl,
Arrays.asList(scope))
.build();
// Point or redirect your user to the authorizationUrl.
System.out.println("Go to the following link in your browser:");
System.out.println(authorizationUrl);
// Read the authorization code from the standard input stream.
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("What is the authorization code?");
String code = in.readLine();
System.out.println(code);
// End of Step 1 <--
// Step 2: Exchange -->
GoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(
httpTransport, jsonFactory, clientId, clientSecret, code, redirectUrl).execute();
// End of Step 2 <--
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setClientSecrets(clientId, clientSecret)
.build()
.setFromTokenResponse(tokenResponse);
People peopleService = new People.Builder(httpTransport, jsonFactory, credential)
.build();
}
你在哪裏設置'clientSecrect'變量? – mikeyq6
您是否閱讀過上述變量的註釋,//轉到Google Developers Console,打開應用程序的憑證頁面,然後複製客戶端ID和客戶端密鑰。 //然後將它們粘貼到以下代碼中。檢查你的谷歌控制檯。 –
對不起卡爾帕納,但我找不到clientSecrect那裏。我只有clientId。 –