2015-07-10 23 views
2

我正在嘗試使用適用於iOS的新面料twitter套件。 登錄後,我們可以要求用戶允許訪問電子郵件ID,如果允許,然後返回登錄用戶的電子郵件,但它給我錯誤。無法使用twitter結構從twitter獲取用戶的電子郵件iOS框架

Email (null), Error: Error Domain=NSURLErrorDomain Code=-1001 
"The request timed out." UserInfo=0x7fdd314f1c30 
{NSUnderlyingError=0x7fdd314d9aa0 "The request timed out.", 
NSErrorFailingURLStringKey=https://api.twitter.com/1.1/account/verify_cre 
dentials.json?skip_status=true&include_email=true, 
NSErrorFailingURLKey=https://api.twitter.com/1.1/account/verify_credentia 
ls.json?skip_status=true&include_email=true, 
NSLocalizedDescription=The request timed out.} 

而這裏是我的代碼,我試圖從他們的文檔。

if ([[Twitter sharedInstance] session]) { 
    TWTRShareEmailViewController* shareEmailViewController = 
    [[TWTRShareEmailViewController alloc] 
    initWithCompletion:^(NSString* email, NSError* error) { 
     NSLog(@"Email %@, Error: %@", email, error); 
    }]; 
    [self presentViewController:shareEmailViewController 
         animated:YES 
        completion:nil]; 
} else { 
    // TODO: Handle user not signed in (e.g. 
    // attempt to log in or show an alert) 
} 

我的代碼有什麼問題嗎?請幫幫我。 我可以將我的狀態和媒體發佈到Twitter,但無法獲取電子郵件ID。

任何人都可以請幫我解決這個問題嗎?我也是新來的發展。

+0

你的應用程序是否被推特列入白名單 –

+0

我不明白,他們是什麼意思,白名單,我不這麼認爲。 – Nij

+0

結帳This post http://stackoverflow.com/a/30477261/4395879 –

回答

1

要獲取用戶的電子郵件地址,應將您的應用程序列入白名單。這裏是link。去use this form。您可以發送郵件至[email protected],並提供一些關於您的應用程序的詳細信息,如消費者密鑰,應用程序商店鏈接,隱私政策鏈接,元數據,關於如何登錄我們的應用程序的說明等。他們將在2-3個工作日內回覆。

這裏的故事,我是怎麼交談列入白名單與Twitter的支持團隊:

  • 發送郵件至[email protected]與您應用如消費鍵,應用程序的App Store的鏈接,鏈接到隱私的一些細節政策,元數據,關於如何登錄我們的應用程序的說明。在郵件中提到您想要在您的應用內訪問用戶電子郵件地址。

  • 他們會檢查您的應用程序並在2-3個工作日內回覆您。

  • 一旦他們說你的應用被列入白名單,在Twitter開發者門戶中更新你的應用的設置。登錄apps.twitter.com和:

    1. 在「設置」選項卡,添加服務條款和隱私權政策網址
    2. 的條款在「權限」選項卡,更改您令牌的範圍,申請通過電子郵件。只有當您的應用獲得白名單時,纔會看到此選項。

把雙手放在代碼

Twitter的框架的使用:

獲得用戶的電子郵件地址

-(void)requestUserEmail 
    { 
     if ([[Twitter sharedInstance] session]) { 

      TWTRShareEmailViewController *shareEmailViewController = 
      [[TWTRShareEmailViewController alloc] 
      initWithCompletion:^(NSString *email, NSError *error) { 
       NSLog(@"Email %@ | Error: %@", email, error); 
      }]; 

      [self presentViewController:shareEmailViewController 
           animated:YES 
          completion:nil]; 
     } else { 
      // Handle user not signed in (e.g. attempt to log in or show an alert) 
     } 
    } 

獲取用戶的個人資料

-(void)usersShow:(NSString *)userID 
{ 
    NSString *statusesShowEndpoint = @"https://api.twitter.com/1.1/users/show.json"; 
    NSDictionary *params = @{@"user_id": userID}; 

    NSError *clientError; 
    NSURLRequest *request = [[[Twitter sharedInstance] APIClient] 
          URLRequestWithMethod:@"GET" 
          URL:statusesShowEndpoint 
          parameters:params 
          error:&clientError]; 

    if (request) { 
     [[[Twitter sharedInstance] APIClient] 
     sendTwitterRequest:request 
     completion:^(NSURLResponse *response, 
         NSData *data, 
         NSError *connectionError) { 
      if (data) { 
       // handle the response data e.g. 
       NSError *jsonError; 
       NSDictionary *json = [NSJSONSerialization 
             JSONObjectWithData:data 
             options:0 
             error:&jsonError]; 
       NSLog(@"%@",[json description]); 
      } 
      else { 
       NSLog(@"Error code: %ld | Error description: %@", (long)[connectionError code], [connectionError localizedDescription]); 
      } 
     }]; 
    } 
    else { 
     NSLog(@"Error: %@", clientError); 
    } 
} 

希望它有幫助!

相關問題