Search code examples
iosobjective-cinstagram

Instagram Signed API Call from iOS


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 user can make 60 Follow per hour. My question is how to make Signed API call?

I tried this method as described on Instagram http://instagram.com/developer/restrict-api-requests/ and Make Enforced header enable .and Sent X-Insta-Forwarded-For header field with valid Id, but still after 20 follow it is showing limit error. Can anyone please help me to how to make Signed API call?


Solution

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