我有一个通过 OAuth 2.0 连接到 Facebook 的 iOS 应用程序。我想发出一个 POST 请求,该请求在 iOS 中实现与此代码等效的功能:
curl -F 'access_token=...' \
-F 'message=Hello. I like this new API.' \
https://graph.facebook.com/[USER_ID]/feed
我在网上找到了一个很好的教程,并且按照所有说明进行操作,但我仍然可以让我的 POST 请求正常工作。这是我的代码:
NSString *post = post_text.text;
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
//NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *ready_post = [NSString stringWithFormat:@"https://graph.facebook.com/1313573269/feed?message=%@&access_token=CAACEdEose0cBAHgdZAon2EZBZCzjoLkhg7jrqvZAbliuoOQ2E2Exc4rZCAxPzeVEADwnQaNLYuG16Gq6q6LLLLLLLLVQ7LZAncXCc53qE2iyzleZAPXGajsgjnBTuo6YdJCZAxVGIYYD8sZCgQ9ypZCo0iOZBNuyrechBfee2yptlK9tmgdosZA7wrKg8ZD", postData];
[request setURL:[NSURL URLWithString:ready_post]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
正如您所看到的,我暂时对访问 token 进行硬编码,只是作为测试。但我似乎无法让我的应用程序实际向 Facebook 发布任何内容。
谢谢,丹。
最佳答案
关于ios - iOS 上的 POST 请求 - 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18632714/