Linkedin Invitation API内部服务器错误

时间:2014-05-12 09:29:23

标签: php api linkedin

哟!

我正在尝试使用linkedin邀请api,以允许用户使用电子邮件地址从我的应用程序中连接到linkedin。我能找到人,访问api等等。我不能让邀请工作。我正在使用php(Laravel)。

我基于来自linkedin文档(Linkedin Invite API)的示例。我使用JSON(包含与其示例相同的信息)在帖子中发送我的数据。

我请求使用w_messages,post post和我的变量包含正确的信息。结果我收到了内部服务器错误。

$data = array(
        "recipients" => array(
                "values" => array(
                    "person" => array(
                        "_path" => "/people/email=".$email,
                        "first-name" => $firstname,
                        "last-name" => $lastname
                        )
                    )
            ),
        "subject" => "Bla",
        "body"=> "BlaBLa", 
        "item-content" => array(
                "invitation-request" => array(
                        "connect-type" => "friend"
                    )
            )
        ); 

    $dataString = json_encode($data);

    $opts = array('http' =>
        array(
            'method'  => 'POST',
            'header'  => "Content-type: application/json\r\n".
                          "Connection: close\r\n" .
                          "Content-length: " . strlen($dataString) . "\r\n",
            'content' => $dataString
        )
    );

    $params = array('oauth2_access_token' => Session::get('access_token'),
        'format' => 'json'
        );


    $url = "https://api.linkedin.com/v1/people/~/mailbox".'?' . http_build_query($params);
    $context = stream_context_create($opts);
    $result = file_get_contents($url, false, $context);
    Log::info($result);

    return Response::json(array("invite" => "sent"));

我认为我做错了什么但不知道该往哪里看。

1 个答案:

答案 0 :(得分:0)

看起来你手动执行此操作,是否尝试使用过试用过的?经过测试的第三方库,如simple-linkedinphp - 一个基于PHP的LinkedIn API包装器。

https://code.google.com/p/simple-linkedinphp/wiki/Reference

用法:

// Connect
$API_CONFIG = array(
  'appKey'       => '<your application key here>',
  'appSecret'    => '<your application secret here>',
  'callbackUrl'  => NULL 
);
$linkedin = new LinkedIn($API_CONFIG);

// Send Invite
$linkedin->invite($method, $recipient, $subject, $body, $type = 'friend');

Doc:https://code.google.com/p/simple-linkedinphp/wiki/Reference