2016-04-11 11 views
1

Ich versuche, einen Link auf verlinkt mit LinkedIn Share API mit access token über PHP GUZZLE. Unten ist mein Code.Buchung linkedIn mit access_token über php guzzle

$client = new GuzzleHttp\Client(['base_uri' => 'https://api.linkedin.com']); 
    $access_token = 'AQWJ0aksdlfjhadfsjjfksasdfasfdHBIJvTUGa_t_3FvaqZPnrsMACC-JyPvpL2GBANlOMLUBSK8OEyfUl9_VLoxVe4ACBePysj-_WHv1-PP-Q-xas2owrngUtlq9P7Z2o95XUiO-Xhd9y0bm36DX9JXyxW-3jV2uBwP9pLJDC_FRZQ2JiCE'; 
    $req = $client->request('POST', '/v1/people/~/shares?format=json', [ 
       'headers'   => ["Authorization: Bearer " . $access_token . "\r\n" . "x-li-format: json\r\n" ], 
       'client_id'  => '77g514g0o223322v44', 
         'client_secret' => 'iXadQhy2323jpzPbz7Js', 
       'json'  => [ 'json' =>[ 
           'comment' => "Check out developer.linkedin.com!", 
           'content' => [ 
             "title" => "LinkedIn Developers Resources", 
             "description" => "Leverage LinkedIn's APIs to maximize engagement", 
             "submitted-url" => "https://developer.linkedin.com", 
             "submitted-image-url" => "https://example.com/logo.png" 
             ], 
           'visibility' => ['code' => 'anyone'] 
           ] 
          ] 
      ]); 
    var_dump($req->getStatusCode()); 

Aber es ist mir immer Unauthorized response mit 401 Code zu geben.

Ich weiß, ich mache etwas falsch wo. Jede Hilfe, wo ich mich irre ..

Antwort

1

unten ist Code, wie ich mein Problem lösen, hoffe, es wird auch anderen helfen.

$body = new stdClass(); 
$body->comment = "Check out https://github.com/faisalahsan"; 
$body->content = new stdClass(); 
$body->content->title = "Test ABCasdfadsf"; 
$body->content->description = "My Open Source Contribution"; 
$body->content->{'submitted-url'} = "https://github.com/faisalahsan"; 
$body->content->{'submitted-image-url'} = "https://avatars0.githubusercontent.com/u/8427383?v=3&s=460"; 
$body->visibility = new stdClass(); 
$body->visibility->code = "anyone"; 

$body_json = json_encode($body, true); 

$client = new GuzzleHttp\Client(['base_uri' => 'https://api.linkedin.com']); 
$access_token = 'AQWJ0bPoW9VpPrEYWvywLk2cx1fhwysjaadsfjja#fsExHBIJvTUGa_t_3FvaqZPnrsMACC-JyPvpL2GBANlOMLUBSK8OEyfUl9_VLoxVe4ACBePysj-_WHv1-PP-Q-xas2owrngUtlq9P7Z2o95XUiO-Xhd9y0bm36DX9JXyxW-3jV2uBwP9pLJDC_FRZQ2JiCE'; 

$req = $client->request('POST', '/v1/people/~/shares?format=json', [ 
     'headers'   => ["Authorization" => "Bearer " . $access_token, 
        "Content-Type" => "application/json", 
          "x-li-format"=>"json"], 
     'client_id'  => '77gasdfkjo22v44', 
       'client_secret' => 'iXadQ123askdfzPbz7Js', 
     'body'  => $body_json 
    ]); 
var_dump($req); 
die; 
+0

Vielen Dank, Ihr Code hat mir geholfen, herauszufinden, wie Sie Anrufe zu Linkedin mit guzzle machen. – kevinabraham