【问题标题】:Parse error: syntax error, unexpected ':', expecting ',' or ')' in C:\xampp\htdocs\php\order\instagramapi.php on line 28解析错误:第 28 行 C:\xampp\htdocs\php\order\instagramapi.php 中的语法错误、意外的 ':'、期待 ',' 或 ')'
【发布时间】:2018-11-06 17:53:28
【问题描述】:

为什么我在以下代码中出现上述错误,是语法不正确,我正在使用 Instagram 进行授权。

 public function getAccessTokeAndUserDetails($code){
    $postFields = array(

        'client_id' => $this->clientId,
        'client_secret' => $this->clientSecret,
        'grant_type' => "authorization_code",
        'redirect_uri' => $this->redirectURI,
        'code' => $code
    );

    $ch = curl_init();
    curl_setopt($ch, option:CURLOPT_URL,value:"https://api.instagram.com/oauth/access_token");//line 28
    curl_setopt($ch, option:CURLOPT_RETURNTRANSFER, value:1);
    curl_setopt($ch, option:CURLOPT_SSL_VERIFYHOST, value:0);
    curl_setopt($ch, option:CURLOPT_SSL_VERIFYPEER, value:0);
    curl_setopt($ch, option:CURLOPT_POST, value:1);
    curl_setopt($ch, option:CURLOPT_POSTFIELDS, $postFields);

    $response = curl_exec($ch);
    curl_close($ch);

    return json_decode($response,assoc:true);

}

【问题讨论】:

  • value:option: 等 - 你在哪里找到这个语法?看起来您已经设法从 IDE 复制了一些提示。您只需要提供参数的实际值,而不是参数名称。

标签: php curl oauth-2.0


【解决方案1】:
    public function getAccessTokeAndUserDetails($code){
        $postFields = array(

            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'grant_type' => "authorization_code",
            'redirect_uri' => $this->redirectURI,
            'code' => $code
        );

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,"https://api.instagram.com/oauth/access_token");//line 28
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

    $response = curl_exec($ch);
    curl_close($ch);

    return json_decode($response,assoc:true);

}

optionvalue 不需要在那里。它就像文档中的占位符。文件是指职位。它是一个函数,因此您需要知道将哪些值传递给此函数才能工作,最重要的是按什么顺序。

【讨论】:

    猜你喜欢
    • 2012-05-27
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 2016-12-28
    • 2010-12-20
    • 2014-01-16
    相关资源
    最近更新 更多