我想使用谷歌的人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。 –