如何使用php在linkedin上自动发布状态,获取错误调用未定义的函数http()


How to auto publish status on linkedin using php,getting error Call to undefined function http()

我正在尝试在Linkedin上自动托管,并遵循本教程:http://www.tricksofit.com/2015/09/get-user-access-token-for-linkedin#.Vy13KYR97IU

我得到这个错误:

致命错误:在第23行调用C:''xammp''examp''htdocs''linkedin''one''callback.php中未定义的函数http()

请有人帮我解决它。

require_once("OAuth.php");
$data = array(
'consumer_key' => 'xxxxxxxxxxxxx',
'consumer_secret' => 'xxxxxxxxxxx',
'callback_url' => 'http://localhost/linkedin/one/callback.php'
);
if(isset($_REQUEST['oauth_verifier'])){
$data['oauth_token'] = $_SESSION['oauth_request_token'];
$data['oauth_token_secret'] = $_SESSION['oauth_request_token_secret'];
$method = new OAuthSignatureMethod_HMAC_SHA1();
$consumer = new OAuthConsumer($data['consumer_key'],     $data['consumer_secret']);
$token = new   OAuthConsumer($data['oauth_token'],$data['oauth_token_secret']);
$args = array();
$request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', "https://api.linkedin.com/uas/oauth/accessToken", $args);
$request->set_parameter("oauth_verifier", $_REQUEST['oauth_verifier']);
$request->sign_request($method, $consumer, $token);
 $request = http($request->to_url(),false);
function http($url, $post_data = null) {
    $ch = curl_init();
    if(defined("CURL_CA_BUNDLE_PATH"))
    curl_setopt($ch, CURLOPT_CAINFO, CURL_CA_BUNDLE_PATH);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    if(isset($post_data))
    {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    }
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}
parse_str($request, $token);
$tokens = new OAuthConsumer($token['oauth_token'],     $token['oauth_token_secret'], 1);
$access_token = serialize($tokens);
}

当您在另一个函数中定义一个函数时,就会发生undefined function错误。

function foo() {
    $request = http();
    echo $request;
    function http() {
        return "aaa";
    }
}
foo();

您需要在当前功能范围之外定义http()

function foo(){
    $request = http();
    echo $request;
}
function http() {
    return "aaa";
}
foo();