New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retrieve user's email (again) #364

Closed
TheExcalibur opened this Issue Jun 15, 2015 · 44 comments

Comments

Projects
None yet
@TheExcalibur

TheExcalibur commented Jun 15, 2015

Hi,
I've done every thing with Twitter policies to have my website on Twitter's whitelist.
(https://dev.twitter.com/rest/reference/get/account/verify_credentials)
My app tells me it's "OK", I can get the user's email. But when I make this, I can't find any email.
I did this:

$user_infos = $twitter_conn->get("account/verify_credentials", ['include_entities' => true, 'skip_status' => true, 'include_email' => true]);

Have you any suggestion to get it ?
Regards

@abraham

This comment has been minimized.

Owner

abraham commented Jun 15, 2015

That looks correct. Make sure the access token was granted after email access was enabled. You might need to revoke access and authorize again.

@TheExcalibur

This comment has been minimized.

TheExcalibur commented Jun 15, 2015

I cleared everything on my twitter test account many times and renew the consumer_key and consumer_secret.

Is there any function to get the email or just doing something like $user_infos->email (same way for screen_name) will work ?

@abraham

This comment has been minimized.

Owner

abraham commented Jun 15, 2015

I would guess it would just be ->email but I've never used that API so I have no idea.

@TheExcalibur

This comment has been minimized.

TheExcalibur commented Jun 16, 2015

ok thanks. If any news, I will inform you right here.
Anyway, thanks for your work. It's help a lot ;)

@SrPatinhas

This comment has been minimized.

SrPatinhas commented Dec 28, 2015

@TheExcalibur you get this working? as i saw the user need to have the account verified? could you help me out please? :)

@abraham

This comment has been minimized.

Owner

abraham commented Dec 28, 2015

Yes, a Twitter profile will have to have a confirmed email address for this to work. Some users only sign up with their phone number.

@TheExcalibur

This comment has been minimized.

TheExcalibur commented Dec 28, 2015

Yes. It works with a verified account only

@abraham

This comment has been minimized.

Owner

abraham commented Dec 28, 2015

Note that verified accounts are different from accounts with verified emails. Accounts with verified emails is what matters here.

@SrPatinhas

This comment has been minimized.

SrPatinhas commented Dec 29, 2015

@TheExcalibur @abraham so just do something like

$user_infos = $twitter_conn->get("account/verify_credentials", ['include_entities' => true, 'skip_status' => true, 'include_email' => true]);
$user_infos->email

and it will retrieve the email?

@abraham

This comment has been minimized.

Owner

abraham commented Dec 29, 2015

Assuming the app has been whitelisted by Twitter to access users email addresses, yes, that looks like it should work.

@austinh

This comment has been minimized.

austinh commented Jan 12, 2016

I can't seem to get the email correctly, I have permission from twitter, and using just the GET RESP API works fine, but when using this API it doesnt seem to work.

@abraham

This comment has been minimized.

Owner

abraham commented Jan 12, 2016

What do you mean by "this API"? Which REST API method works and what API method doesn't work?

@dandrits

This comment has been minimized.

dandrits commented Jan 14, 2016

Hello @abraham I've tried what @SrPatinhas suggests by invoking $arr=$connection->get("account/verify_credentials", ['include_entities' => true, 'skip_status' => true, 'include_email' => true]);
and then get $arr->email or something but can't get something like email and arr does not bring any data(but those: public 'code' => int 89 public 'message' => string 'Invalid or expired token.') Of cource my app is whitelisted by twitter and can retrieve emails(as a matter of fact app on profile says "Can rear toyw email address" or something like that).
What am I doing wrong? Shall I invoke it right after your suggestion about $my_tweets = $connection->get('statuses/user_timeline', array('screen_name' => $screenname, 'count' => 5));

thx!

@abraham

This comment has been minimized.

Owner

abraham commented Jan 14, 2016

If you are getting 'code' => int 89 public 'message' => string 'Invalid or expired token.' then you need to get new credentials for the account.

@dandrits

This comment has been minimized.

dandrits commented Jan 14, 2016

Do I have to change my access token or must I change my account's username/password

@abraham

This comment has been minimized.

Owner

abraham commented Jan 14, 2016

The accounts access token being used is invalid. You need a new access token.

@dandrits

This comment has been minimized.

dandrits commented Jan 14, 2016

OK thanks a lot!!

@dandrits

This comment has been minimized.

dandrits commented Jan 15, 2016

@abraham I 've changed the account's token of my app. But the results are the same. I' ve followed the examples about thw api and just after creating a new connection to twitter using my consumer api key/secret using
$connection = new Abraham\TwitterOAuth\TwitterOAuth($twitter_CONSUMER_KEY, $twitter_CONSUMER_SECRET, $_SESSION['token'], $_SESSION['token_secret']);
I've received the access token from twitter using:
$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
Finally I 've made one get call in order to receive user email like the following:
$user = $connection->get("account/verify_credentials", ['include_entities' => true, 'skip_status' => true, 'include_email' => true]);
but I'm getting the error described before for invalid token

thank you for the help and your patience! 🍻

@abraham

This comment has been minimized.

Owner

abraham commented Jan 15, 2016

It's probably not the app's consumer key/secret that is bad, it's probably the user's access token. Make sure you are following the full authentication process to get a user's access token.

@dandrits

This comment has been minimized.

dandrits commented Jan 20, 2016

I'm sorry for my late response. The problem was a firewall issue and now it is solved. Thank you very much for the help! Keep up the great work!! 🍻

@minamoto19

This comment has been minimized.

minamoto19 commented Mar 3, 2016

Just wanted to let people know that the code below doesn't always return the email address even if you are whitelisted and the user's email is verified.
get("account/verify_credentials", ['include_entities' => true, 'skip_status' => true, 'include_email' => true]);
Do not include the parameter values as booleans. Use strings instead. This works every time in my application.
Eg.
get("account/verify_credentials", ['include_email' => 'true']);
Put the parameter's value in double or single quote(depends on your code) to be sent as a string.

@abraham

This comment has been minimized.

Owner

abraham commented Mar 3, 2016

Interesting. (string) true yields "1" so I'm guessing some of Twitter's servers are accepting 1 as truthy and some are not. A possible improvement for this library is to iterate parameters and if they are true|false replace them with "true"|"false".

@abraham abraham reopened this Mar 3, 2016

@abraham abraham added the Task label Mar 3, 2016

@dandrits

This comment has been minimized.

dandrits commented Mar 3, 2016

hhm that's why sometimes I was getting results and some others not,interesting!

@usamaejaz

This comment has been minimized.

usamaejaz commented Mar 6, 2016

Right. I also wasted a lot of time with this issue. Setting true to 'true' (string) gave the expected result. 😮

@minamoto19

This comment has been minimized.

minamoto19 commented Mar 7, 2016

@abraham
I don't think this is a task that has to do with this project.
Its a handle error on twitter part. Or at least they should have state that in their documentation.
I like how light this library is. No need for extra checks.
But after all its your project so you decide.

@abraham

This comment has been minimized.

Owner

abraham commented Mar 7, 2016

I think it is an issue the library needs to fix. Twitter explicitly documents true as the expected value (not 1) and because of PHP unexpected coercion Twitter doesn't get the documented parameters. I could add a note to the docs but most people would miss it.

@arifchenko

This comment has been minimized.

arifchenko commented Mar 8, 2016

Finally, i found the solution for 1.1 version. Find your OAuth.php file, on function from_consumer_and_token, add array value "include_email" => "true" and it has to be quoted on true to parse this as a string, not 1 as a result. Actually, the main thing is to call the API including this parameter. Then you can get email address with $user_info->email command or whatever variables you use. I hope this could help.

@minamoto19

This comment has been minimized.

minamoto19 commented Mar 8, 2016

@arifchenko
We are talking about the current version but even for 1.1 what you suggest seems the wrong way to go.
Basically what you suggest is to hardcore an argument value($parameters).
That way you request email in your every call even if you don't need it.
You can use the $parameters array argument to set "include_email" => "true" when you call from_consumer_and_token function
Please someone correct me, if I'm wrong.

@abraham

This comment has been minimized.

Owner

abraham commented Mar 9, 2016

v0.1.1 is a very old version of TwitterOAuth. If you are using it you should upgrade to the latest one. It has a lot of bug fixes and improvements. That being said you shouldn't ever need to call methods outside of TwitterOAuth.php directly.

@abuzant

This comment has been minimized.

abuzant commented Mar 24, 2016

@abraham I have noticed a comment that says "if you're app is authorized to get the email, you will get it".. I am using the correct verion of the library and the (string) value for TRUE but still the email is noe being sent back and no errors at all. Everything works great but I am not getting the email, so How do I get my app to be authorized?

Example usage of code:
$user = $connection->get("account/verify_credentials", ["include_entities" => 'false', "skip_status" => 'true', "include_email" => 'true']);

@abraham

This comment has been minimized.

Owner

abraham commented Mar 24, 2016

@abuzant

This comment has been minimized.

abuzant commented Mar 24, 2016

I can't be more shy of myself. I have been on that page since the morning and never saw that line about white-listing an application. I am so sorry and thank you so much. (thumbsup)

@daniel-seitz

This comment has been minimized.

daniel-seitz commented Jul 22, 2016

Trying to figure out how to programatically revoke our app's access since some of our users already granted the access before we were white listed for the email address. The user's experience is better if that is done on the back end. Is there a function in your lib?

The Twitter doc says

Your app will need to regenerate the user access tokens for previously authenticated users to access their email address.

Other than oauth2/invalidate_token - which is the wrong one - I can't find how...

@apuestaya

This comment has been minimized.

apuestaya commented Jan 4, 2017

finally, solved with this:

$TW_user = $connection->get("account/verify_credentials",['include_email' => "true"]);
Thanks @abraham

@abraham abraham added this to the v1.0 milestone Feb 23, 2017

@vebinua

This comment has been minimized.

vebinua commented Jun 20, 2017

I may still be using the old version but changing the parameter values from boolean to string indeed did the trick.

$getParam = array('include_email' => 'true', 'include_entities' => 'false', 'skip_status' => 'true'); $user = $connection->get("account/verify_credentials", $getParam);

Thank you @abraham

@johnross7392

This comment has been minimized.

johnross7392 commented Jul 11, 2017

I have confirmed my email address, checked the request email permission option and added the privacy policy and TOS urls... it even shows can request users email address in the app settings page, but still shows cannot view email address in my auth dialog box.. did i miss anything?

@razorsharpshady

This comment has been minimized.

razorsharpshady commented Mar 12, 2018

hey @abraham , please make the change in api for 'true'.
and if possible also add trim filter in access token and consumer secret key.

@deepanchakravarthi

This comment has been minimized.

deepanchakravarthi commented Mar 30, 2018

Hi Abraham, I tried it as per your documentation and comments. I didn't get email address. Could you please let me know - how can I get it? Thank you!

For your info, still I'm getting the error -> [code] => 89 [message] => Invalid or expired token

My Code:
use Abraham\TwitterOAuth\TwitterOAuth;
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
$params = array('include_email' => 'true', 'include_entities' => 0, 'skip_status' => 1);
$data = $connection->get("account/verify_credentials", $params);
print_r($data);
Note: I tried, 'include_email' => 'true', 'include_email' => "true", 'include_email' => '1', 'include_email' => "1", 'include_email' => true, 'include_email' => 1 :)

I have regenerated Consumer Key & Consumer Secret.

@razorsharpshady

This comment has been minimized.

razorsharpshady commented Mar 30, 2018

@deepanchakravarthi

This comment has been minimized.

deepanchakravarthi commented Mar 30, 2018

@razorsharpshady Thank you for your comments
screenshot-2018-3-30 twitter application management
Kindly check my screenshot

@deepanchakravarthi

This comment has been minimized.

deepanchakravarthi commented Mar 30, 2018

@abraham Regarding your comment, If you are getting 'code' => int 89 public 'message' => string 'Invalid or expired token.' then you need to get new credentials for the account.

Yes I'm getting the same. I regenerated key and secret. But there is no change in response, I can get screen name and user_id using the access token. Could not get email address.. Kindly guide me to get it. Thank you!

@deepanchakravarthi

This comment has been minimized.

deepanchakravarthi commented Mar 30, 2018

Oh my god, finally I solved it. I had been struggling for the past 3 hours. :(

My guys, I hope it helps for you if you get the same issues in the near future. :)

My Code:

(Error code)
use Abraham\TwitterOAuth\TwitterOAuth;
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));

I used oauth_token and oauth_token_secret from access_token.
(Successful Code)
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
$user = $connection->get("account/verify_credentials", ['include_email' => 'true', 'include_entities' => 'false', 'skip_status' => 'true']);
var_dump($user);
$params = array('include_email' => 'true', 'include_entities' => 0, 'skip_status' => 1);
$data = $connection->get("account/verify_credentials", $params);
print_r($data);

It's working.

@razorsharpshady

This comment has been minimized.

razorsharpshady commented Mar 30, 2018

@deepanchakravarthi what wrong was u doing?

@deepanchakravarthi

This comment has been minimized.

deepanchakravarthi commented Mar 30, 2018

@razorsharpshady I used oauth_token and oauth_token_secret - session values instead of using access token.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment