【问题标题】:Instagram comments API can't add 'text' valueInstagram 评论 API 无法添加“文本”值
【发布时间】:2012-02-21 07:00:04
【问题描述】:

我请求的网址是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 上?

非常感谢!

【问题讨论】:

    标签: ios instagram


    【解决方案1】:

    我正在使用混合身份验证,这是代码,它正在工作..

    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;
    }
    

    【讨论】:

      【解决方案2】:

      要将 cmets 添加到 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 数据。

      【讨论】:

      • 谢谢,但我能够通过将“文本”作为 httpRequest 的 htmlBody 来解决问题。虽然能够将 access_token 放在 URL 中。
      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          【解决方案5】:

          我相信这里的关键是 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) 一样简单: text=My%20 评论

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-05-27
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多