I need to use LinkedIn API to share media. I currently arrived to get token and get profile data. So the problem is I'm not able to post media in that url "https://api.linkedin.com/v2/ugcPosts".
I want to do that but in my case it's not working
I created a class with methods. I can't put all my code because is too long but I can detail you what is function role, so
login_url() -> Allow me to get code
set_access_token() -> Allow me to exchange code with access_token
set_user_urn - > Allow me to set user_urn usefull to post data in share function. My urn code is like XXXXXX-XXX. Tell me if it's good format
public function share() {
    $url = "https://api.linkedin.com/v2/ugcPosts" . $this->_access_token;
    $fields = '{
        "author": "urn:li:person:' . $this->_urn_id . '",
        "lifecycleState": "PUBLISHED",
        "specificContent": {
            "com.linkedin.ugc.ShareContent": {
                "shareCommentary": {
                    "text": "Hello World! This is my first Share on LinkedIn!"
                },
                "shareMediaCategory": "NONE"
            }
        },
        "visibility": {
            "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
        }
    }';
var_dump($fields);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    $httpCode = curl_getinfo($curl , CURLINFO_HTTP_CODE); // this results 0 every time
    $response = curl_exec($curl);
    if ($response === false) 
        $response = curl_error($curl);
    echo stripslashes($response);
    curl_close($curl);
}
I get the following error message:
{ "author": "urn:li:person:XXXXXX-XXX", "lifecycleState": "PUBLISHED", "specificContent": { "com.linkedin.ugc.ShareContent": { "shareCommentary": { "text": "Hello World! This is my first Share on LinkedIn!" }, "shareMediaCategory": "NONE" } }, "visibility": { "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC" } }" {"message":"Request timed out","status":504}