java - connect endpoints-backend and android client with oauth2 -
i have problem when intent authorized android app @apimethod in endpoint. read lot of documentation, didn't resolved problem.
the principal error see in logs googleauthexception: unknown.
i have created project in google developers console, 2 clients_id 1 android , 1 audience/web_id.
my client code in android:
mcredential = googleaccountcredential.usingaudience(this,"server:client_id:"+constants.web_client_id); chooseaccount();
in onactivityresult account name:
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); switch (requestcode) { case request_account_picker: if (data != null && data.getextras() != null) { string accountname = data.getextras().getstring( accountmanager.key_account_name); if (accountname != null) { mcredential.setselectedaccountname(accountname); } } break; }
then create asynctask call endpoint method , add credentials:
bpmapiregister.builder builder = new bpmapiregister.builder(androidhttp.newcompatibletransport(),new jacksonfactory(),mcredential) .setrooturl(constants.cloud_url)//https://project_id.appspot.com/_ah/api/ .setapplicationname("bpm"); user user = createuser(); bpmapiregister registerapi = builder.build(); try { return registerapi.create(user).execute();//problem here } catch (exception e) { e.printstacktrace(); }
the endpoint code:
@api(name = "bpmapiregister",version = "v1",resource = "users", namespace = @apinamespace( ownerdomain = "backend.myapplication.example.com", ownername = "backend.myapplication.example.com", packagepath = "" )) public class userregisterendpoint { private static final logger logger = logger.getlogger(userregisterendpoint.class.getname()); @apimethod(name = "create",path="users",httpmethod = apimethod.httpmethod.post, scopes = {backendconstants.email_scope}, clientids = { backendconstants.web_client_id, backendconstants.android_client_id, constant.api_explorer_client_id}, audiences = {backendconstants.android_audience}) public user create(user user, com.google.appengine.api.users.user userauth) throws oauthrequestexception {
the error in execute endpoint method:
04-25 11:00:11.655 19784-19927/com.android.app w/system.err﹕ com.google.android.gms.auth.googleauthexception: unknown 04-25 11:00:11.655 19784-19927/com.android.app w/system.err﹕ @ com.google.android.gms.auth.googleauthutil.gettoken(unknown source) 04-25 11:00:11.655 19784-19927/com.android.app w/system.err﹕ @ com.google.android.gms.auth.googleauthutil.gettoken(unknown source)
to create android client_id, have obtained fingerprint , put package com.android.app(my app package).
to create web_id, put 2 url's http://localhost:8080 , https://project_id.appspot.com; , our respective redirect url adding /oauth2callback
Comments
Post a Comment