首页 > 解决方案 > 解析错误:第 28 行 C:\xampp\htdocs\php\order\instagramapi.php 中的语法错误、意外的 ':'、期待 ',' 或 ')'

问题描述

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

}

标签: phpcurloauth-2.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);

}

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


推荐阅读