Unable to get email from twitter

ios

#1

I’m not able to get email from twitter, I already request for special
permission from twitter to access email. Android they got email from
twitter with the same account.I’m not sure what I’m doing wrong , can
anybody help me to fix it out.(I’m using fabric kit for twitter).
My code as

[[Twitter sharedInstance] logInWithCompletion:^
(TWTRSession *session, NSError *error) {

     if (session) {
         NSLog(@"user id%@", [session userID]);
         NSLog(@"user name%@", [session userName]);
         NSLog(@"auth token %@", [session authToken]);
         NSLog(@"auth token secret%@", [session authTokenSecret]);

         
         userId = [session userID];
         
         [[[TWTRAPIClient alloc]init] loadUserWithID:[session userID] completion:^(TWTRUser* _Nullable user ,  NSError *_Nullable error){
             NSLog(@"%@", user);
             userName = [user name];
             
             TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];
             NSURLRequest *request = [client URLRequestWithMethod:@"GET"
                                                              URL:@"https://api.twitter.com/1.1/account/verify_credentials.json"
                                                       parameters:@{@"include_email": @"true", @"skip_status": @"true"}
                                                            error:nil];
             
             [client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

                 NSLog(@"success");
             }];
         }];
         
         NSLog(@"Twitter signed in as -> name = %@ id = %@ ", [session userName],[session userID]);
         [self performSelector:@selector(loginTwitter) withObject:nil afterDelay:6.0];
     } else {
         NSLog(@"Error: %@", [error localizedDescription]);
     }
 }];

}


#2

Hey @AhmadRafique11,

If you’ve previously authenticated Twitter within your app, then you would need to revoke access through your Twitter account’s settings, then re-authorize the app.

-Mike


#3

Hey @bonnell!, Thanks for your response, I have re-authorized the app, but still not getting the email.
I have an issue in this api response.
client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
//[self.view hideToastActivity];

                 NSLog(@"success");

}];

When this api runs, and in success function, I got this response,

Printing description of response:
<NSHTTPURLResponse: 0x7f7f8e463aa0> { URL: https://api.twitter.com/1.1/account/verify_credentials.json?skip_status=true&include_email=true } { status code: 200, headers {
“Cache-Control” = “no-cache, no-store, must-revalidate, pre-check=0, post-check=0”;
“Content-Disposition” = “attachment; filename=json.json”;
“Content-Encoding” = gzip;
“Content-Length” = 551;
“Content-Type” = “application/json;charset=utf-8”;
Date = “Fri, 18 Nov 2016 14:33:13 GMT”;
Expires = “Tue, 31 Mar 1981 05:00:00 GMT”;
“Last-Modified” = “Fri, 18 Nov 2016 14:33:13 GMT”;
Pragma = “no-cache”;
Server = “tsa_o”;
Status = “200 OK”;
“Strict-Transport-Security” = “max-age=631138519”;
“x-access-level” = “read-write-directmessages”;
“x-connection-hash” = 8c979aa2c31d9b06e21823399fdd883d;
“x-content-type-options” = nosniff;
“x-frame-options” = SAMEORIGIN;
“x-rate-limit-limit” = 75;
“x-rate-limit-remaining” = 73;
“x-rate-limit-reset” = 1479480457;
“x-response-time” = 117;
“x-transaction” = 00d62790008f2fb0;
“x-twitter-response-tags” = “BouncerExempt, BouncerCompliant”;
“x-xss-protection” = “1; mode=block”;
} }

I think, this response is incorrect maybe.


#4

Yea, I’m not seeing the email that would have been included. Can you email into support(at)fabric(dot)io with the Twitter Consumer Key that you’re using? Just reference this thread.
-Mike


#5

Thanks @bonnell for your response, But I am still unable to get the email, I have also updated the access tokens, but still getting the same response as above.

Please guide me if I am doing something wrong.

Thanks…!


#6

Hey @AhmadRafique11,

The team’s been out due to holidays and a long weekend. I saw your email response and will reply there.

-Mike


#7

Hi @Bonnel,

Hope you will be fine…!
I am here to say Thank you for your response, I have seen your email in which you said that all permissions are set. I appreciate it.

But I am sorry to say that I am still unable to get the Email. :disappointed_relieved:
Now I will explain my complete procedure, may be you will understand my problem.

The Complete Procedure:-

"Basically, I am using a twitter app, created by another person. He created the twitter app on apps.twitter.com.
He is using the app for android and I am using his app consumer key and consumer secret in my iPhone app.
He is getting the email successfully , but I am not.

    Now Actually, I have integrated the twitter integration in my iPhone app using Fabric following this tutorial:
    https://fabric.io/kits/ios/twitterkit

    In this tutorial, it is mentioned that add the following code into your app info.plist file as show in this screenshot:
    https://cloudup.com/c5GTYGNFhf1

Now My First problem is that:

I have pasted the consumer key and consumer secret in my info.plist file which I got from my Android friend, These are the keys of the Twitter App created at apps.twitter.com.
This is my code of info.plist file:

   <key>Fabric</key>
       <dict>
	       <key>APIKey</key>
	       <string>redacted</string>
	       <key>Kits</key>
	       <array>
		       <dict>
			       <key>KitInfo</key>
			       <dict>
				       <key>consumerKey</key>
				       <string>redacted</string>
				       <key>consumerSecret</key>
				       <string>redacted</string>
			       </dict>
			       <key>KitName</key>
			       <string>Twitter</string>
		       </dict>
	       </array>
       </dict>

I have also pasted these keys in AppDelegate.m file as below:

[[Twitter sharedInstance] startWithConsumerKey:@“redacted” consumerSecret:@“redacted”];
[Fabric with:@[[Twitter class]]];

Now my 2nd Question is that:

  • Fabric also have consumer key and consumer secret key, In my app, where should I place these keys generate by Fabric. ???

     Please see the screenshot:    https://cloudup.com/c2Av8u5hbtx
    
     Currently I am only using the Consumer key and Consumer Secret of the Twitter app created at apps.twitter.com.
    
     I have also checked the Request email addresses from users box under the Permission tab. 
     Please see the screenshot:-    https://cloudup.com/cBtfzrk1YYO
    

Finally,

this is my code, when login with Twitter button is pressed…!

   [[Twitter sharedInstance] logInWithCompletion:^
 (TWTRSession *session, NSError *error) {
     if (session) {
            
          [[[TWTRAPIClient alloc]init] loadUserWithID:[session userID] completion:^(TWTRUser* _Nullable user ,  NSError *_Nullable error){
             TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];

             NSURLRequest *request = [client URLRequestWithMethod:@"GET"

                                                              URL:@"https://api.twitter.com/1.1/account/verify_credentials.json"

                                                       parameters:@{@"include_email": @"true", @"skip_status": @"true"}

                                                            error:nil];

             

             [client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

                 if (connectionError) {

                     NSLog(@"error: %@",connectionError.localizedDescription);

                 }

                 else{

                     NSLog(@"success");

                 }

             }];

         }];

Response:

And I am getting the following response:-
<NSHTTPURLResponse: 0x7fb0f39532b0> { URL: https://api.twitter.com/1.1/account/verify_credentials.json?skip_status=true&include_email=true } { status code: 200, headers {
“Cache-Control” = “no-cache, no-store, must-revalidate, pre-check=0, post-check=0”;

"Content-Disposition" = "attachment; filename=json.json";

"Content-Encoding" = gzip;

"Content-Length" = 548;

"Content-Type" = "application/json;charset=utf-8";

Date = "Thu, 01 Dec 2016 12:11:09 GMT";

Expires = "Tue, 31 Mar 1981 05:00:00 GMT";

"Last-Modified" = "Thu, 01 Dec 2016 12:11:09 GMT";

Pragma = "no-cache";

Server = "tsa_o";

Status = "200 OK";

"Strict-Transport-Security" = "max-age=631138519";

"x-access-level" = "read-write-directmessages";

"x-connection-hash" = af6c8e28d7c91c917ed2719d868c89d4;

"x-content-type-options" = nosniff;

"x-frame-options" = SAMEORIGIN;

"x-rate-limit-limit" = 75;

"x-rate-limit-remaining" = 73;

"x-rate-limit-reset" = 1480594514;

"x-response-time" = 139;

"x-transaction" = 007d638800a56ec2;

"x-twitter-response-tags" = "BouncerExempt, BouncerCompliant";

"x-xss-protection" = "1; mode=block";

} }

The response says that it is success, but it contains no email of the user. Now that is the issue.

I hope you understand what is my real problem is ???
Please guide me in the right direction. I really appreciate your response…!

Thanks…!


#8

Hey @AhmadRafique11,

I’m going to take a look at this but I’ve edited your post to remove any keys. Please do not post these in public places. We may also want to consider replacing your current keys.


#9

Hi @Bonnel,

   Thanks for editing my keys, I will take care of this in future, Please guide me to solve my email problem. 

Also thanks for your response…!


#10

Hey @AhmadRafique11,

I’ve gone through this a couple of times and I think there are a couple of things going on. First I’d recommend using a unique set of Twitter Consumer Key and Secret per app. If the Android app is working with the key you originally mentioned was from apps.twitter.com, then use that for the Android app. However for the iOS app, I’ve whitelisted your key that was created on the Fabric Twitter dashboard. Please update to using that key and secret in your app’s info.plist Also, then make sure you’re not initializing Fabric with a different Twitter Consumer Key and Secret. After making those changes, run a clean, build and run of your project. De-authorize the app for an account you’re testing with, then try re-logging in and let me know how it goes.

Hope that’s all cleared up, let me know if there’s anything confusing or if I can help with anything else.

-Mike