无法获取friendList

时间:2015-09-30 11:31:29

标签: ios swift facebook-graph-api fbsdk

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 个答案:

答案 0 :(得分:1)

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

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

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);
     }];
}

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

<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>

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

在info.plist中添加以下Transport Securtiy

Undefined property: stdClass::$number

答案 1 :(得分:0)

根据最新的sdk:这只会返回任何使用过(通过Facebook登录)申请的朋友。

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

答案 2 :(得分:0)

最新的FB SDK无法访问未使用您应用的Facebook好友。 您只会列出正在使用您的应用的朋友。

答案 3 :(得分:0)

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