Instagram 评论 API 无法添加“文本”价值

发布于 2025-01-07 08:54:55 字数 542 浏览 5 评论 0原文

我请求的 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 需要两个参数:textaccess_token。我已经提供了两者,但收到错误消息,指出 text 丢失。

我尝试过使用不同的符号而不是 & 但没有任何效果。有人知道 text 参数应如何出现在请求的 URL 上吗?

多谢 !

My requested URL is https://api.instagram.com/v1/media/MYMEDIA_ID/comments?access_token=MYTOKEN&text=MYTEXT

I get a reply like this:

{
    meta =     {
        code = 400;
        "error_message" = "Missing 'text'";
        "error_type" = APIInvalidParametersError;
    };
}

In the Instagram document it says the comment API takes two parameters: text and access_token. I have provided both, and I get the error saying text is missing.

I have tried with different symbols instead of & but nothing works. Does anybody have experience on how the text parameter should appear on the requested URL?

Thanks a lot !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

秉烛思 2025-01-14 08:54:55

我正在使用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;
}

i am using hybridauth, and here is the code, it is working..

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;
}
白鸥掠海 2025-01-14 08:54:55

要向 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 数据。

To add comments to Instagram you need to post the text it shouldn't be part of the URL. The Instagram API documentation provides an example using CURL:

curl -F 'access_token=1084932.f59def8.deb7db76ffc34f96bada217fe0b6cd9a' \
     -F 'text=This+is+my+comment' \
     https://api.instagram.com/v1/media/{media-id}/comments

So neither the access_token or the text are part of the URL just POST data.

冷了相思 2025-01-14 08:54:55

只需将 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.
}];

Just add text=MYTEXT to your request's HTTPBody.

Here is sample code:

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.
}];
坦然微笑 2025-01-14 08:54:55

您需要更改请求的内容类型 ContentType="comment"

you need to change the content type of the request ContentType="comment"

真心难拥有 2025-01-14 08:54:55

我相信这里的关键是 ContentType 标头。至少在我开始定义它之前,没有什么对我有用。

如果您设置 "ContentType": "multipart/form-data" 您需要设置相当复杂的正文内容,如下所述:
https://dotnetthoughts.net/post-requests-from-azure-logic -apps/

我发现更简单的路径:
设置标头 "Content-Type": "application/x-www-form-urlencoded"

,然后您可以将请求正文设置为简单的 key=url_escaped(value):
文字=我的%20评论

I believe the key here is ContentType header. At least nothing worked for me until I started to define it.

If you set "ContentType": "multipart/form-data" you need to set up quite a complex body content as described here:
https://dotnetthoughts.net/post-requests-from-azure-logic-apps/

I found much easier path:
Set your header "Content-Type": "application/x-www-form-urlencoded"

and then you can set your request body as simple as key=url_escaped(value):
text=My%20comment

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文