如何在android studio中使用URL Shortener API客户端库?
我在我的Android应用程序中使用Google+登录,我想向我的web服务器发送身份验证令牌 [ 并使用以下代码生成idToken如何在android studio中使用URL Shortener API客户端库?,android,google-api,google-oauth,google-url-shortener,google-plus-signin,Android,Google Api,Google Oauth,Google Url Shortener,Google Plus Signin,我在我的Android应用程序中使用Google+登录,我想向我的web服务器发送身份验证令牌 [ 并使用以下代码生成idToken private class GetIdTokenTask extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { String accountName = Plus.
private class GetIdTokenTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
String scopes = "audience:server:client_id:" + Constants.SERVER_CLIENT_ID; // Not the app's client ID.
String idToken = "";
try {
idToken = GoogleAuthUtil.getToken(getApplicationContext(), account, scopes);
} catch (IOException e) {
Log.e(TAG, "Error retrieving ID token.", e);
} catch (GoogleAuthException e) {
Log.e(TAG, "Error retrieving ID token.", e);
}
return idToken;
}
@Override
protected void onPostExecute(String result) {
authToken=result;
Log.i(TAG, "ID token: " + result);
}
}
后端程序员建议我使用
urlshortener和
userinfo.email
要得到那种代币。我怎样才能得到这种代币?
我正在使用GoogleAppClient连接google plus和驱动api,代码如下:
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addApi(Plus.API)
.addScope(new Scope("profile"))
.addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mGoogleApiClient.connect();
}
});
如何以我上面描述的缩短格式获取auth令牌
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addApi(Plus.API)
.addScope(new Scope("profile"))
.addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mGoogleApiClient.connect();
}
});