Fetch Facebook Mutual friends between me and another User

前端 未结 2 346
有刺的猬
有刺的猬 2021-01-27 17:37

i want to fetch Facebook Mutual friends in my ios App

this is my try to get mutual friends i call with this Link

[NSString stringWithFormat:@\"me/mutua         


        
相关标签:
2条回答
  • 2021-01-27 18:20

    Yes, quite easy solution i have for you.

    NSString *myFriendId = [NSString stringWithFormat:@"/%@",#YourFriendId#];
    
    
        NSString *hashedAccessToken = [self hmac:accessToken withKey:kAPP_SECRETE];
        NSDictionary *params = @{
                                 @"fields" : @"context.fields(mutual_friends)",
                                 @"appsecret_proof" : hashedAccessToken,
                                 @"access_token" : accessToken
                                 };
    
    
        /* make the API call */
        [FBRequestConnection startWithGraphPath:myFriendId parameters:params  HTTPMethod:@"GET" completionHandler:^
         (
          FBRequestConnection *connection, id result, NSError *error
          ){//Handle Respons;}];
    

    And here is the hmac function (Add #import )

    //SHA256 HASHMAC
    - (NSString *)hmac:(NSString *)access_token withKey:(NSString *)app_secret
    {
        const char *cKey  = [app_secret cStringUsingEncoding:NSASCIIStringEncoding];
        const char *cData = [access_token cStringUsingEncoding:NSASCIIStringEncoding];
        unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
        CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
        NSData *HMACData = [NSData dataWithBytes:cHMAC length:sizeof(cHMAC)];
        const unsigned char *buffer = (const unsigned char *)[HMACData bytes];
        NSMutableString *HMAC = [NSMutableString stringWithCapacity:HMACData.length * 2];
        for (int i = 0; i < HMACData.length; ++i){
            [HMAC appendFormat:@"%02x", buffer[i]];
        }
        return HMAC;
    }
    
    0 讨论(0)
  • 2021-01-27 18:21

    You're using the wrong endpoint syntax, as @CBroe already pointed out, and which is also clear from the docs.

    You need to use

    /{user-id}.context/mutual_friends
    

    The {user-id} is the user you're interested in, and the "other" user is the one which Access Token was used for the request. This ONLY works for users which are both already users of your app.

    0 讨论(0)
提交回复
热议问题