Fetch Facebook Mutual friends between me and another User

前端 未结 2 345
有刺的猬
有刺的猬 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;
    }
    

提交回复
热议问题