我请求的URL是https://api.instagram.com/v1/media/MYMEDIA_ID/comments?access_token=MYTOKEN&text=MYTEXT
我得到这样的回复:
{
meta = {
code = 400;
"error_message" = "Missing 'text'";
"error_type" = APIInvalidParametersError;
};
}
在Instagram文档中,它表示评论API采用了两个参数:text
和access_token
。我已经提供了这两个,但我得到了一个错误,说text
丢失了。
我试过用不同的符号代替&
,但都不起作用。有人知道text
参数应该如何出现在请求的URL上吗?
非常感谢!
我正在使用hybridauth,这是代码,它正在工作。。
function setUserComment($post_id, $message)
{
$flag = 0;
$parameters = array("text" => $message);
$response = $this->api->post( "media/$post_id/comments", $parameters );
// check the last HTTP status code returned
if ( $this->api->http_code != 200 ){
throw new Exception( "Comment failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ) );
}
else{
$flag = 1;
}
return $flag;
}
要在Instagram上添加评论,您需要发布文本,它不应该是URL的一部分。Instagram API文档提供了一个使用CURL:的示例
curl -F 'access_token=1084932.f59def8.deb7db76ffc34f96bada217fe0b6cd9a'
-F 'text=This+is+my+comment'
https://api.instagram.com/v1/media/{media-id}/comments
因此,access_token和文本都不是URL的一部分,只是POST数据。
只需将text=MYTEXT添加到请求的HTTPBody中。
这是示例代码:
NSMutableURLRequest *apiRequest = [[NSMutableURLRequest alloc] initWithURL:apiURL];
apiRequest.HTTPMethod = @"POST";
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"text=%@", MYTEXT] dataUsingEncoding:NSUTF8StringEncoding]];
apiRequest.HTTPBody = body;
[NSURLConnection sendAsynchronousRequest:apiRequest queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
// Handle the response.
}];
您需要更改请求的内容类型ContentType="comment"
我相信这里的关键是ContentType标头。在我开始定义它之前,至少没有什么对我有用
如果设置"ContentType":"multipart/form-data",则需要设置相当复杂的正文内容,如下所述:https://dotnetthoughts.net/post-requests-from-azure-logic-apps/
我找到了一条更容易的路:设置标题"内容类型":"application/x-www-form-urlencoded"
然后您可以将请求主体设置为key=url_escaped(value)这样简单:text=我的%20comment