简体   繁体   English

使用Twitter API获取电子邮件

[英]Get email with Twitter API

I've already asked for elevated permissions to Twitter and they granted to me. 我已经要求提高对Twitter的权限,并将它们授予了我。 So now I have to get the email for user registration but I don't know how. 因此,现在我必须获取用于用户注册的电子邮件,但我不知道如何。 This is what I have, someone know how should I do it? 这就是我所拥有的,有人知道我应该怎么做?

if(isset($_REQUEST['oauth_token']) && $_SESSION['token'] == $_REQUEST['oauth_token']) {

    //Successful response returns oauth_token, oauth_token_secret, user_id, and screen_name
    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['token'] , $_SESSION['token_secret']);
    $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier'], ["include_entities" => 'true', "skip_status" => 'true', "include_email" => 'true']);

    if($connection->http_code == '200')
    {
        //Redirect user to twitter
        $_SESSION['status'] = 'verified';
        $_SESSION['request_vars'] = $access_token;

        //Unset no longer needed request tokens
        unset($_SESSION['token']);
        unset($_SESSION['token_secret']);
        header('Location: twconfig.php');
    }else{
        die("Ha surgido un error, por favor inténtelo denuevo más tarde.");
    }

}

If Twitter just give you the elevated privileges, you need to make sure that you have regenerated your tokens. 如果Twitter仅授予您提升的特权,则需要确保您已重新生成令牌。

In addition any user token created before you had elevated privileges will not provide the email. 此外,在提升特权之前创建的任何用户令牌都不会提供电子邮件。 Users will have to authorize the application another time. 用户将不得不再次授权该应用程序。

Twitter has decided that because they wanted to make sure that users are aware that they are sharing their email. Twitter之所以决定这样做,是因为他们想确保用户知道他们正在共享他们的电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM