解析错误:语法错误,第28行的C:\ xampp \ htdocs \ php \ order \ instagramapi.php中出现意外的':',期望为','或')'

时间:2018-11-06 09:44:55

标签: php curl oauth-2.0

为什么在以下代码中出现上述错误,语法不正确,我正在使用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);

}

1 个答案:

答案 0 :(得分:0)

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

}

选项不需要存在。就像文档中的占位符一样。文档指的是职位。这是一个函数,因此您需要知道传递给该函数的值才能起作用,并且最重要的是按哪个顺序。