Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 用于用户配置文件信息的oauth2.0_Android_Oauth 2.0_Google Oauth - Fatal编程技术网

Android 用于用户配置文件信息的oauth2.0

Android 用于用户配置文件信息的oauth2.0,android,oauth-2.0,google-oauth,Android,Oauth 2.0,Google Oauth,如何使用oauth2.0在android应用程序上获取用户的google个人资料信息。我需要android应用程序的正确代码/示例。我需要用户信息,如: 个人资料照片 生日 性别 位置 感谢Google OAuth需要执行以下步骤: 1.向谷歌注册。注册后,在安装的应用程序部分,您将获得您的重定向URI和客户端ID 2.以上获得的重定向URI和客户端ID将用于以下url https://accounts.google.com/o/oauth2/auth?" + "scope=https%3A%2

如何使用oauth2.0在android应用程序上获取用户的google个人资料信息。我需要android应用程序的正确代码/示例。我需要用户信息,如:

  • 个人资料照片
  • 生日
  • 性别
  • 位置

  • 感谢

    Google OAuth需要执行以下步骤:

    1.向谷歌注册。注册后,在
    安装的应用程序
    部分,您将获得您的
    重定向URI
    客户端ID

    2.以上获得的
    重定向URI
    客户端ID
    将用于以下url

    https://accounts.google.com/o/oauth2/auth?" + "scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile"+ "&redirect_uri=" + REDIRECT_URI + "&response_type=code" +"&client_id=" + CLIENT_ID;
    
    3.此url将带您进入谷歌认证页面,在此由谷歌接管,您将输入您的帐户详细信息。此外,它被重定向到approval页面,用户允许你的应用程序使用他们的google数据

    4.现在,作为对这一点的回应,您可以从google获得作为JSON或html页面标题的
    ACCESS code
    。解析
    访问代码

    5.使用
    访问代码
    您现在将使用以下POST数据发出
    POST
    请求,以获取
    访问令牌

    'code' // this is the access code
    'client_id' // same as earlier
    'client_secret' // you will find this on the google page where you registered
    'redirect_uri' // same as earlier
    'grant_type' = "authorization_code" // as is
    
    6.您现在将在JSON中获得访问令牌,作为“访问令牌”。解析此访问令牌

    7.使用访问令牌对以下url进行调用

    https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=your_access_token_here
    
    8.您将以JSON的形式获得用户数据作为对该调用的响应

    以下是您可能需要的其他文档:

    我已经尝试了很久了。。。但是我不知道如何为它编码。我正在尝试使用GoogleAuthUtil.getToken()非常感谢!。。你的步骤帮助我完成了任务。我用过谷歌。关于这方面的文档不多。我将尽快为其他人提供我的代码。:)嘿,如果你已经这样做了,请你分享一下,你是怎么想到这个的。