代码之家  ›  专栏  ›  技术社区  ›  Manoj Govindan

在使用OAuth验证用户的Twitter身份之后,有没有办法获得用户的电子邮件ID?

  •  85
  • Manoj Govindan  · 技术社区  · 15 年前

    http://api.twitter.com/1/account/verify_credentials.xml . 响应包含用户id、屏幕名称等,但不包含电子邮件id。

    是否可以检索用户的电子邮件ID?

    更新

    extended permissions . Twitter也有类似的功能吗?

    9 回复  |  直到 10 年前
        1
  •  106
  •   DWRoelands    10 年前

    无法通过API检索用户的电子邮件地址。这是API团队经过深思熟虑的设计决策。

    可以向用户请求电子邮件地址,但需要将应用程序列入白名单。看到了吗 https://dev.twitter.com/rest/reference/get/account/verify_credentials 有关API调用和 this form

        2
  •  16
  •   Val Neekman    13 年前

    为了 OutsourceFactor

    因此,您必须首先创建一个帐户(本地帐户),然后您可以使用任何社会oAuth提供者来简化您将来的登录。这对我的网站来说是最划算的。

        3
  •  3
  •   Moonchild    10 年前

    Twitter在其OAuth响应中混淆了电子邮件地址。这一直是一个伟大的问题,人们希望包括一个“注册Twitter”功能。

    最近(2015年初),Twitter通过第二次服务呼叫增加了电子邮件地址支持,但在某些情况下,被滥用。

    https://dev.twitter.com/rest/reference/get/account/verify_credentials

    所以现在是可能的,但我的意见是继续实现OAuth,除了twitter之外,每个提供商都可以单点登录。他们必须抵制,直到他们正常行动,我的意思是像每一个其他OAuth提供商。

        4
  •  3
  •   bish    10 年前

    在Android中使用 Fabric

    TwitterAuthClient authClient = new TwitterAuthClient();
    
    authClient.requestEmail(session, new Callback<String>() {
    
        @Override
        public void success(Result<String> result) {
            // Do something with the result, which provides the email address
        }
    
        @Override
        public void failure(TwitterException exception) {
          // Do something on failure
        }
    });
    

    看到了吗 http://docs.fabric.io/android/twitter/request-user-email-address.html

        5
  •  1
  •   Syed mohamed aladeen Boldewyn    10 年前

    在我的例子中,每次得到响应时,我都会为每个用户获得一个唯一的身份验证id,每次都是相同的。所以我用这个id创建了一封电子邮件独特的@twitter.com检查我的网站上是否已经有了(第一次没有),然后注册用户。然后,如果他第二次登录,我只是再次创建电子邮件,并检查它是否已经在那里。这样我就不必让他先创建一个本地帐户,就可以识别他登录。

        6
  •  1
  •   Igor Simic    9 年前

    下面是如何在Laravel中获取twitter用户电子邮件的示例 coditty.com

     // get token secret from db 
            $token = TwitterTokens::where('oauth_token', $request->input('oauth_token'))->first(); 
    
    
            // open twitter connection
            $connection = new \Abraham\TwitterOAuth\TwitterOAuth(
                            $this->twitter_consumer_key, 
                            $this->twitter_secret, 
                            $request->input('oauth_token'), 
                            $token->oauth_token_secret// twitter secret from DB
                            );
    
            // get acces token
            $access_token = $connection->oauth("oauth/access_token", ["oauth_verifier" => $request->input('oauth_verifier')]); 
    
             // new TwitterOAuth instance to get email
            $twitterOAuth = new \Abraham\TwitterOAuth\TwitterOAuth( $this->twitter_consumer_key, $this->twitter_secret, $access_token['oauth_token'], $access_token['oauth_token_secret'] );
    
            // Let's get the user's info with email
            $twitterUser = $twitterOAuth->get('account/verify_credentials', ['include_entities' => 'false','include_email'=>'true','skip_status'=>'true',]);
    
    
            // output user object from twitter in your Log file
            Log::info(['user'=>$twitterUser]);
    
        7
  •  0
  •   Community Mohan Dere    8 年前

    检查我的答案 here .

        8
  •  0
  •   Community Mohan Dere    8 年前

    添加此代码!

    $params = array('include_email' => 'true', 'include_entities' => 'false', 'skip_status' => 'true');

    `$data = $connection->get('account/verify_credentials', $params); // get the data`
    

    // getting twitter user profile details $twt_id = $data->id; //twitter user id $twt_email = $data->email; //twitter user email

    签出完整过程 here

        9
  •  0
  •   Emmanuel Ikechukwu    9 年前

    谁说你不能得到用户的电子邮件,从用户请求电子邮件地址复选框下的应用程序权限 apps.twitter.com . 必须在应用程序设置中填写隐私策略URL和服务条款URL字段,才能使用电子邮件地址访问功能。如果启用,用户将通过 oauth/authorize 对话框,您的应用程序可以访问他们的电子邮件地址。