【问题标题】:Instagram Signed API Call from iOS来自 iOS 的 Instagram 签名 API 调用
【发布时间】:2014-10-13 05:02:34
【问题描述】:
为了让 Instagram 发布方法的签名 API 调用来关注用户,比如用户的图像等。用户每小时关注 20 个限制。但是,如果我们进行签名 API 调用,那么用户每小时可以进行 60 次关注。但我的问题是如何进行签名 API 调用。 ?
我尝试了 Instagram http://instagram.com/developer/restrict-api-requests/ 上描述的这种方法,并启用强制标头。并使用有效 ID 发送 X-Insta-Forwarded-For 标头字段。但是在 20 之后仍然显示限制错误。任何人都可以帮助我如何进行签名 API 调用。
提前致谢。
【问题讨论】:
标签:
ios
objective-c
iphone
api
instagram
【解决方案1】:
在搜索了我解决问题的方法后,通过制作我的应用签名应用:
要为 Instagram 用户进行签名 API 调用,需要在他们的 insta 应用程序中选中这两个复选框。管理客户。并且必须关注Implicit OAuth Grant flow。
对于所有关注/喜欢帖子类型的请求用户需要添加一个标题:
类型为
X-Insta-Forwarded-For -> [IP information]|[Signature]
IP 应该是您应用的负载均衡器检测到的客户端远程 IP;
签名是,应用带有 SHA256 的 HMAC,并在此处附加签名的十六进制表示。在IP address 作为数据使用您的clientSecret 作为键。
然后使用管道| 连接 IP 信息和签名并将其设置为标头字段的值。
我使用以下代码生成签名:
-(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"];
因此 API 调用将作为签名 API 调用发送。