在白名單 PHP 之後獲取用戶電子郵件 (Get user email afer whitelist PHP)


問題描述

在白名單 PHP 之後獲取用戶電子郵件 (Get user email afer whitelist PHP)

我正在使用 PHP Twitter 登錄系統 & 我已請求將我的 Twitter 應用程序列入 Twitter 白名單,以便當用戶在我的網站上註冊 Twitter 時,我可以收到他的電子郵件。

我的應用程序已成功列入白名單,但我沒有找到任何教程如何在 PHP 代碼中獲取電子郵件。

index.php 代碼的一部分://Variables del usuario

        $tw_name        = $_SESSION['request_vars']['screen_name'];
        $tw_id          = $_SESSION['request_vars']['user_id'];
        $oauth_key      = $_SESSION['request_vars']['oauth_token'];
        $oauth_secret_key = $_SESSION['request_vars']['oauth_token_secret'];

        $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_key, $oauth_secret_key);
        $my_data = $connection‑>get('users/show', array('screen_name' => $tw_name, 'user_id'=> $tw_id));
        $my_tweets = $connection‑>get('statuses/user_timeline', array('screen_name' => $screen_name, 'count' => 10));       
        $my_email = $connection‑>get('account/verify_credentials', array('screen_name' => $tw_name, 'user_id'=> $tw_id,'include_email'=>true));

echo '<strong>Name:</strong> '.$my_data‑>name.
        '<br><strong>Date: </strong> ' .$my_data‑>created_at.
        '<br><strong>Description:</strong> ' .$my_data‑>description.
        '<br><strong>Location:</strong> ' .$my_data‑>location.
        '</br><strong>Lenguage:</strong> '.$my_data‑>lang.'<br>';
        echo $my_email‑>email;

我可以看到名稱、日期等,但是我無法使用用戶電子郵件,幫助


參考解法

方法 1:

What's the content of dumping $my_email? It could be a error or a described behaviour, in the twitter docs:

"When set to true email will be returned in the user objects as a string. If the user does not have an email address on their account, or if the email address is un‑verified, null will be returned."

It could be the case?

If no, you could try doing this way:

$my_email = $connection‑>get("account/verify_credentials", ['include_entities' => true, 'skip_status' => true, 'include_email' => true]);

or simply:

get("account/verify_credentials", ['include_email' => true]);

With pure booleans instead of strings, found here: https://github.com/abraham/twitteroauth/issues/364 and reading the official documention: https://dev.twitter.com/rest/reference/get/account/verify_credentials it makes sense.

If this doesn't work (that it should), in some others places, they use only:

$data = $connection‑>get('account/verify_credentials');

(http://code.runnable.com/UnUm0Nx6Lu1MAAAY/how‑to‑use‑twitter‑oauth‑in‑php‑web‑application‑for‑twitteroauth)

Hope it helps!

(by MW Jose Miguel ChaconJP. Aulet)

參考文件

  1. Get user email afer whitelist PHP (CC BY‑SA 2.5/3.0/4.0)

#twitter #email #PHP






相關問題

用於輕鬆創建 Twitter 位置地理坐標的地圖工具? (Map-tool for easily creating Twitter location geo-coordinates?)

PHP Twitter OAuth - 我無法驗證我的帳戶 (PHP Twitter OAuth - I cannot authenticate my account)

如何設置文本光標在 TWTweetComposeViewController 中的位置? (How to set where the text cursor is in TWTweetComposeViewController?)

如何從 Twitter 檢測成功的身份驗證並在此之後運行一些代碼 (How to detect successful authentication from Twitter and run some code after that)

Cocos2d 2.0 升級後 Twitter 不再工作 (Twitter no longer working after Cocos2d 2.0 upgrade)

在 android (eclipse) 中集成 oAuth twitter 時清除共享首選項 (Clearing shared preferences in case of oAuth twitter integration in android (eclipse))

如何在 twitteR R 包的 getUser 中引用變量名? (How to refer a variable name in getUser in twitteR R package?)

使用 twitteR 包提取 Twitter 句柄而不是屏幕名稱? (Extract Twitter Handles instead of Screen Names using twitteR package?)

在白名單 PHP 之後獲取用戶電子郵件 (Get user email afer whitelist PHP)

多久運行一次 cron 來挖掘 Twitter 公共時間線? (How often to run the cron, to mine twitter public timeline?)

如何從 JQuery 發送到 SQL 數據庫? (How to send from JQuery to SQL database?)

使用 facebook、twitter 等進行身份驗證。合而為一! (Authentication with facebook, twitter, etc.. all in one!)







留言討論