Instagram Signed API Call from iOS

余生颓废 提交于 2019-12-01 01:33:35

After searching for the things I resolved my issue by this, By making my app signed app:

to make Signed API call for Instagram user need to check both the checkbox in their insta App. under manage clients. and Have to follow The Implicit OAuth Grant flow.

For All Follow/Like post type request user need to add one header: of Type as

X-Insta-Forwarded-For -> [IP information]|[Signature]

IP should be it the client's remote IP as detected by the your app's load balancer; Signature is , apply an HMAC with SHA256, and append the hex representation of the signature there . On the IP address as data using your clientSecret as key. Then join IP info and Signature using pipe | and set that as the value of the header field.

I had used the following code to generate Signature:

    -(NSString *)signWithKey:(NSString *)key usingData:(NSString *)data
    {
        const char *cKey  = [key cStringUsingEncoding:NSASCIIStringEncoding];
        const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding];

        unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];

        CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);

        NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];

        return [[HMAC.description stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] stringByReplacingOccurrencesOfString:@" " withString:@""];
    }

-(NSString*)getheaderData
{
 NSString *ipString = [self fetchMyIP];
 NSString *signature = [self signWithKey:kClientSecret usingData:ipString];

}

To set header in iOS:  [request setValue:[self getheaderData] forHTTPHeaderField:@"X-Insta-Forwarded-For"];

So the API call will be sent as the Signed API call.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!