我无法从Google获取一次性授权码.我试图从Android客户端获取授权代码,以便我可以将其发送到我的Rails后端(Web客户端).
在我的Google Cloud Developer Console中,我有一个带有两个客户端ID的应用程序:
Web应用程序的客户端ID(用于我的rails后端)
Android应用程序的客户端ID(对于我的Android客户端).使用的SHA1来自〜/ .android/debug.keystore
假设Web应用程序客户端ID是 12345.apps.googleusercontent.com
假设Android客户端ID是 67890.apps.googleusercontent.com
这是我的一些代码:
private final static String WEB_CLIENT_ID = "12345.apps.googleusercontent.com";
private final static String GOOGLE_CALENDAR_API_SCOPE = "audience:server:client_id:" + WEB_CLIENT_ID;
private void getAndUseAuthToken(final String email) {
AsyncTask task = new AsyncTask<String, Void, String>() {
@Override
protected String doInBackground(String... emails) {
try {
return GoogleAuthUtil.getToken(AddExternalCalendarsActivity.this, emails[0], GOOGLE_CALENDAR_API_SCOPE);
} catch (UserRecoverableAuthException e) {
startActivityForResult(e.getIntent(), IntentConstants.REQUEST_GOOGLE_AUTHORIZATION);
} catch (IOException e) {
e.printStackTrace();
} catch (GoogleAuthException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace(); …Run Code Online (Sandbox Code Playgroud) android ruby-on-rails google-authentication google-cloud-platform
我需要在几个方面使用loopj的SyncHttpClient。当我使用AsyncHttpClient时,请求成功返回。当我按此处接受的答案所示使用SyncHttpClient时:如何使用loopJ SyncHttpClient进行同步调用?,我在中遇到断点onFailure。该的StatusCode为0,错误响应是空的,抛出的java.io.IOException异常:未处理的异常:空。
这是相关的代码。再次,当我使用异步时,它工作正常:
buttonTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// AsyncHttpClient httpClient = new AsyncHttpClient();
SyncHttpClient httpClient = new SyncHttpClient();
httpClient.get("http://10.0.1.6:3000/home/test_endpoint", new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
String stringResponse = response.toString();
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
String error = errorResponse.toString();
}
});
String temp = "got here";
} …Run Code Online (Sandbox Code Playgroud)