簡體   English   中英

如何使用iOS社交框架讀取任何Facebook用戶公共時間軸?

[英]How to read any facebook user public timeline using iOS Social framework?

我真的花了幾個小時嘗試解決這個問題! 我只希望能夠從facebook讀取任何用戶的時間軸(公共消息)...從技術上講(為簡單起見),我寧願僅使用iOS sdk中的框架(即不必使用facebook)。 因此,我目前僅使用Social.framework和Accounts.framework

到目前為止,我成功完成的工作是,當我嘗試通過以下網址@“ https ”中的“ ANOTHER_USER_ID”支持“ me”時,請閱讀當前登錄用戶(在設備上標識的用戶)的Facebook時間軸: //graph.facebook.com/me/feed “,它僅返回一個空的數據字段(無“ message”節點)。

“奇怪”的事實是,我可以使用@“ https://graph.facebook.com/cocacola/feed ”成功訪問任何公司類型的提要(例如“可口可樂”)。

所以我的問題是如何達到“簡單”用戶的提要(例如“ shireesh.asthana”),以便我可以閱讀它的“消息”?

到目前為止,我的過程:

  1. https://developers.facebook.com/上創建一個應用以獲取AppID
  2. 在我的代碼中使用此AppID即可使用SLRequest發送請求

以下是我當前正在使用的代碼:

ACAccountStore *account = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [account
                                  accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    // Specify App ID and permissions
    NSDictionary *options = @{
                              ACFacebookAppIdKey: @"1111111111111", // My AppID here
                              //ACFacebookPermissionsKey: @[@"read_stream"],
                              ACFacebookPermissionsKey: @[@"email", @"read_stream"],
                              ACFacebookAudienceKey:ACFacebookAudienceFriends
                              };

    [account requestAccessToAccountsWithType:accountType
                                     options:options completion:^(BOOL granted, NSError *error)
     {
         if (granted == YES)
         {
             NSArray *arrayOfAccounts = [account
                                         accountsWithAccountType:accountType];

             if ([arrayOfAccounts count] > 0)
             {
                 ACAccount *facebookAccount = [arrayOfAccounts lastObject];

                 // I want the messages and the author
                 NSDictionary *parameters = @{@"fields": @"message,from"};

                 NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/HERE_THE_USER_ID/feed"]; // Work with "cocacola" but not with "shireesh.asthana"

                 SLRequest *getRequest = [SLRequest
                                           requestForServiceType:SLServiceTypeFacebook
                                           requestMethod:SLRequestMethodGET
                                           URL:feedURL 
                                           parameters:parameters];

                 getRequest.account = facebookAccount;

                 [getRequest performRequestWithHandler:
                  ^(NSData *responseData, NSHTTPURLResponse
                    *urlResponse, NSError *error)
                  {
                      dataSource = [NSJSONSerialization
                                    JSONObjectWithData:responseData
                                    options:NSJSONReadingMutableLeaves
                                    error:&error];

                      // Reach the main queue to process result
                      dispatch_async(dispatch_get_main_queue(), ^{
                          NSLog(@"Read %d messages", [dataSource[@"data"] count]);
                          if ([dataSource[@"data"] count] != 0) {
                              // Do stuff in case of success...
                          } else {
                              // Do stuff in case of ERROR...
                          }
                      });
                  }];
             } else {
                 // Case of no facebook account on the device...
             }
         } else {
             // User don't grant the app to access its facebook info...
         }
     }];

所以我的問題是如何達到“簡單”用戶的提要(例如“ shireesh.asthana”),以便我可以閱讀它的“消息”?

原因可能是-

  1. <user>沒有公開帖子,

  2. <user>在“ 應用程序設置”中具有“關閉平台

(當然,這里的<user>不是會話中的用戶)

PS Shireesh Asthana(在Facebook工作),沒有任何公開帖子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM