Instagram Signed API Call from iOS

后端 未结 1 1559
难免孤独
难免孤独 2021-01-07 09:00

To make the Signed API calls for Instagram post methods to Follow user, Like user\'s image etc. Users Have limit of 20 Follow per Hour. But if we make Signed API call then u

相关标签:
1条回答
  • 2021-01-07 10:00

    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.

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