0
var request = FBSDKGraphRequest(graphPath:"/me/friends", parameters: nil);

request.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in
    if error == nil {
        println("Friends are : \(result)")
    } else {
        println("Error Getting Friends \(error)");
    }

----------------------我的日志------------- ------------

Friends are : {
    data =     (
    );
    summary =     {
        "total_count" = 714;
    };
}

我如何获取正在使用此应用程序的用户的 facebook 朋友。请帮忙。任何帮助将不胜感激。提前谢谢。

4

4 回答 4

1

您不能直接从 facebook 获取所有朋友,因为它不允许这些。但是您可以使用以下内容,但是您将无法获得该朋友的 facebook id,您只能获得姓名和个人资料图片

注意:您需要获得 facebook 的批准才能使用 taggable_friends。

var request = FBSDKGraphRequest(graphPath:"/me/taggable_friends", parameters: nil);

您需要检查以下是否成功授予您的权限,然后您可以检查好友列表。

if (FBSession.activeSession.state == FBSessionStateOpen
            || FBSession.activeSession.state == FBSessionStateOpenTokenExtended)
        {
            [self loadFacebookFriends];
        }
        else
        {
            [FBSession openActiveSessionWithReadPermissions:@[@"public_profile,email,user_friends"] allowLoginUI:YES completionHandler:
             ^(FBSession *session, FBSessionState state, NSError *error)
             {
                 if (!error)
                 {
                     if (state == FBSessionStateOpen)
                     {
                         [FBSession setActiveSession:session];

                         [self loadFacebookFriends];

                     }
                     else
                     {
                         NSLog(@"Status :%ld",(unsigned long)state);
                     }
                 }
                 else
                 {
                     // Could not connect
                 }
             }];
        }
-(void)loadFacebookFriends
{
    // SEND REQUEST FOR FRIEND LISTs
    FBRequest* friendsRequest = [FBRequest requestForGraphPath:@"/me/friends"];
    [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary* result,NSError *error)
     {
         [appDelegate activityHide];

         if (error)
         {
             return ;
         }

         NSArray* friends = [result objectForKey:@"data"];
         NSLog(@"Found: %lu friends", (unsigned long)friends.count);
     }];
}

**注意:如果您使用的是 iOS 9,您需要在 info.plist 中为您的应用授予以下权限。您也可以参考此链接https://developers.facebook.com/docs/ios/ios9 **

在您的 info.plist 中添加以下 Transport Securtiy

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>graph.facebook.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
        <key>facebook.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
        <key>fbcdn.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>akamaihd.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fbapi20130214</string>
    <string>fbapi20130410</string>
    <string>fbapi20130702</string>
    <string>fbapi20131010</string>
    <string>fbapi20131219</string>
    <string>fbapi20140410</string>
    <string>fbapi20140116</string>
    <string>fbapi20150313</string>
    <string>fbapi20150629</string>
    <string>fbauth</string>
    <string>fbauth2</string>
    <string>fb-messenger-api20140430</string>
    <string>fb-messenger-platform-20150128</string>
    <string>fb-messenger-platform-20150218</string>
    <string>fb-messenger-platform-20150305</string>
</array>
于 2015-09-30T13:26:37.923 回答
0

根据最新的sdk:这只会返回任何使用(通过Facebook登录)提出请求的应用程序的朋友。

https://developers.facebook.com/docs/graph-api/reference/v2.4/user/friends

于 2015-09-30T12:04:57.933 回答
0

最新的 FB SDK 将无法获取未使用您的应用的 Facebook 好友。您将仅列出那些正在使用您的应用程序的朋友。

于 2015-09-30T12:28:59.770 回答
0

另一件事是我没有得到许可,谢谢你的帮助。

于 2015-10-01T11:37:34.517 回答