ashwinks / PHP-LinkedIn-SDK

A PHP wrapper for the LinkedIn API
94 stars 74 forks source link

POST method issue #11

Closed aCodeAlchemist closed 9 years ago

aCodeAlchemist commented 9 years ago

I try to share using $li->post() method. but browser goes round and round after authorization. It doesn't do anything? any idea what am I doing wrong?

$li = new LinkedIn(
        array(
            'api_key' => 'myKey', 
            'api_secret' => 'mySecret', 
            'callback_url' => 'http://180.211.99.162:9051/widgetapi/oauth/linkedin'
        )
    );

    if(isset($_REQUEST['code'])) {

        $token = $li->getAccessToken($_REQUEST['code']);

        $result = $li->post("/people/~/shares", array(
                                                    "comment"=>"Check out developer.linkedin.com! http://linkd.in/1FC2PyG",
                                                    "visibility" => array("code" => "anyone")
                                                )
                                        );
        debug($result);
    } else {
        $loginUrl = $li->getLoginUrl(array(
                            LinkedIn::SCOPE_WRITE_SHARE
                        )
                    );
        $this->redirect($loginUrl);
    }
}

I debugged curl options and I got following parameters. And everything looks alright. but dont know why this is not working.

Array
(
    [10036] => POST
    [19913] => 1
    [10002] => https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=AQXR8IWG3tv1kJ3NxxTrfhX3Kv8CfTTbRSYNGlb0pBpkSBRp00Ee2lJiIdo4zcQOj5X00N7aJGGe3D2VLs3PPiB__lILvIsPbJ0G78MjfDfX-1-_9gvvmevLe2yDijyfyPiqUXyKdnn9InbwyejZe67omajLnISV9hJZPqBapSNemYMhlwk
    [10023] => Array
        (
            [0] => x-li-format: json
            [1] => Content-Length: 105
            [2] => Content-Type: application/json
        )

    [64] => 
    [52] => 1
    [78] => 20
    [47] => 1
    [10015] => {"comment":"Check out developer.linkedin.com! http:\/\/linkd.in\/1FC2PyG","visibility":{"code":"anyone"}}
)
marceloj commented 9 years ago

Try this

if(isset($_GET['code'])) { $_REQUEST['code'] = $_GET['code']; $token = $li->getAccessToken($_REQUEST['code']); $token_expires = $li->getAccessTokenExpiration();

$sComentario = $modelPublicacionLinkedin->sTitulo; $sContenido = array('title' => $modelPublicacionLinkedin->sTitulo, 'description' => $modelPublicacionLinkedin->sMensaje, 'submitted_url' => $_SESSION['img2']); $sVisiblePara = 'anyone'; $sVisible = array('code' => $sVisiblePara);

$json = array('comment' => $sComentario ,
          'content' => $sContenido,
          'visibility' => $sVisible);

$PostShare_People = $li->post('/people/~/shares', $json); echo '

' . print_r($PostShare_People,1) . '
';

Marcelo Jáuregui

On Fri, Feb 20, 2015 at 2:18 AM, Jay Shah notifications@github.com wrote:

I try to share using `$ln->post()' method. but browser goes round and round after authorization. It doesn't do anything? any idea what am I doing wrong?

$li = new LinkedIn( array( 'api_key' => 'myKey', 'api_secret' => 'mySecret', 'callback_url' => 'http://180.211.99.162:9051/widgetapi/oauth/linkedin' ) );

if(isset($_REQUEST['code'])) {

    $token = $li->getAccessToken($_REQUEST['code']);

    $result = $li->post("/people/~/shares", array(
                                                "comment"=>"Check out developer.linkedin.com! http://linkd.in/1FC2PyG",
                                                "visibility" => array("code" => "anyone")
                                            )
                                    );
    debug($result);
} else {
    $loginUrl = $li->getLoginUrl(array(
                        LinkedIn::SCOPE_WRITE_SHARE
                    )
                );
    $this->redirect($loginUrl);
}

}

— Reply to this email directly or view it on GitHub https://github.com/ashwinks/PHP-LinkedIn-SDK/issues/11.

marceloj commented 9 years ago

And use LinkedIn::SCOPE_READ_WRTIE_UPDATES,

Marcelo Jáuregui

On Sat, Feb 21, 2015 at 12:53 PM, Marcelo Jauregui < MarceloJauregui@gmail.com> wrote:

Try this

if(isset($_GET['code'])) { $_REQUEST['code'] = $_GET['code']; $token = $li->getAccessToken($_REQUEST['code']); $token_expires = $li->getAccessTokenExpiration();

$sComentario = $modelPublicacionLinkedin->sTitulo; $sContenido = array('title' => $modelPublicacionLinkedin->sTitulo, 'description' => $modelPublicacionLinkedin->sMensaje, 'submitted_url' => $_SESSION['img2']); $sVisiblePara = 'anyone'; $sVisible = array('code' => $sVisiblePara);

$json = array('comment' => $sComentario ,
          'content' => $sContenido,
          'visibility' => $sVisible);

$PostShare_People = $li->post('/people/~/shares', $json); echo '

' . print_r($PostShare_People,1) . '
';

Marcelo Jáuregui

On Fri, Feb 20, 2015 at 2:18 AM, Jay Shah notifications@github.com wrote:

I try to share using `$ln->post()' method. but browser goes round and round after authorization. It doesn't do anything? any idea what am I doing wrong?

$li = new LinkedIn( array( 'api_key' => 'myKey', 'api_secret' => 'mySecret', 'callback_url' => 'http://180.211.99.162:9051/widgetapi/oauth/linkedin' ) );

if(isset($_REQUEST['code'])) {

    $token = $li->getAccessToken($_REQUEST['code']);

    $result = $li->post("/people/~/shares", array(
                                                "comment"=>"Check out developer.linkedin.com! http://linkd.in/1FC2PyG",
                                                "visibility" => array("code" => "anyone")
                                            )
                                    );
    debug($result);
} else {
    $loginUrl = $li->getLoginUrl(array(
                        LinkedIn::SCOPE_WRITE_SHARE
                    )
                );
    $this->redirect($loginUrl);
}

}

— Reply to this email directly or view it on GitHub https://github.com/ashwinks/PHP-LinkedIn-SDK/issues/11.

aCodeAlchemist commented 9 years ago

@marceloj Not working! Sorry!