linkedin-api-php-client icon indicating copy to clipboard operation
linkedin-api-php-client copied to clipboard

Avoid getting the "Syntax error" from json_decode

Open mnajafzadeh opened this issue 6 years ago • 5 comments

Avoid getting the "Syntax error" from json_decode when LinkedIn API returns an empty response.

mnajafzadeh avatar Nov 07 '18 07:11 mnajafzadeh

@mnajafzadeh could you provide an example when you did run into such issue?

zoonman avatar Nov 07 '18 17:11 zoonman

Hi @zoonman

An example can be, when you try to post a comment on a LinkedIn company page like:

$response = $client->post("companies/".$company_id."/updates/key=".$updateKey."/update-comments-as-company/", ['comment' => $message]);

This kind of requests have not any response if it is successful.

Thank you.

mnajafzadeh avatar Nov 15 '18 05:11 mnajafzadeh

👍

albertleao avatar Jan 29 '19 06:01 albertleao

Hi @zoonman

An example can be, when you try to post a comment on a LinkedIn company page like:

$response = $client->post("companies/".$company_id."/updates/key=".$updateKey."/update-comments-as-company/", ['comment' => $message]);

This kind of requests have not any response if it is successful.

Thank you.

This is not the correct fix for your issue.

https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/ugc-post-api

The UGC Post is created with a 201 Created response and the response header X-RestLi-Id contains the ugcPost ID.

Linkedin does give response but it's in the header not body. We should parse the response correctly.

soisme avatar Feb 01 '19 20:02 soisme

Hi

In my case, the problem was resolved by changing the API Root URL to version 2.

    $this->client = new Client(
        env('LINKEDIN_CLIENT_ID'),
        env('LINKEDIN_CLIENT_SECRET')
    );

    $this->client->setApiRoot('https://api.linkedin.com/v2/');

    $this->client->setRedirectUrl(env('LINKEDIN_CALLBACK'));

reichert-lucas avatar Apr 06 '21 12:04 reichert-lucas