Google Account login Integration for android Xamarin

我的梦境 提交于 2019-11-29 01:39:12

问题


I need to integrate google login to android xamarin application. gone through the code from bellow link: http://motzcod.es/post/67077106339/google-plus-services-login-and-1-in-xamarin-android

it shows the error connection failed and [GooglePlayServicesUtil] Google Play Store is missing. even ofter adding google play service(Froyo) component.

even i gone through the bellow links https://developers.google.com/+/mobile/android/sign-in

Android: Login using google account?

Google Login For Android App

but this is related to android eclipse using java code. can anybody suggest me how to do this in xamarin. any hints/links are appreciated. thank you.


回答1:


Finally i got a solution by doing the research over the available codes from xamarin forum and stackoverflow. I made use of the OAuth2Authenticator

  1. Register in google developer console as webapplication instead of installed application(android)* provide the redirect url with valid url ("http://abcd.com/xyz.aspx") same should be used in the application code.

  2. On authentication complete it will return access_token

  3. By using the access_token make the REST request to get user complete information (https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + accessTokenValue + “.)

  4. Deserialize the json response to get information in object.

*If we registered in developer console as installed application(like android) after making OAuth2Authenticator request it will show window with message please copy this code switch to your application and paste it there [code] manually need to close the window and proceed to authentication. to get ride of this webapplication type is choosen.

Refer for more info. : Login by google account integration for Xamarin.Android and Xamarin.iOS




回答2:


The answer given is great. It works without trouble so long as that redirecturi is a real and accessible url for the underlying WebView to connect to at the end of the flow. In a mobile scenario this really doesn't make sense but google requires it. The examples typically say use localhost as the redirecturi which leads to a 401 UnAuthorized response showing in the UI. Ugh. Authentication is successful, but you have this ugly box you have to click on.

My solution on this was to have the redirecturi be the me link, https://www.googleapis.com/plus/v1/people/me. The code you have completes, there are no errors and the view is dismissed. Hope this helps somebody.



来源:https://stackoverflow.com/questions/25520180/google-account-login-integration-for-android-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!