|
Matteo Lerone - 2017-03-06 04:58:52 - In reply to message 50 from thirupathi reddy
Hello, I am new and I am trying your classes. I was trying to post something on my Linkedin account and I used this code.
I think the problem is a "FailOnAccessError" but I don't know how to fix it.
**************************
require('LinkedIn/http.php');
require('LinkedIn/oauth_client.php');
$client = new oauth_client_class;
$client->debug = false;
$client->debug_http = true;
$client->server = 'LinkedIn2';
$client->redirect_uri = 'http://localhost/loginlinkedin/index.php';
if(defined('OAUTH_PIN'))
$client->pin = OAUTH_PIN;
$client->client_id = '78570sx7umqwaw'; $application_line = __LINE__;
$client->client_secret = 'OLY9cIBY5RICNI0E';
/* API permission scopes
* Separate scopes with a space, not with +
*/
$client->scope = 'r_basicprofile r_emailaddress w_share';
if(strlen($client->client_id) == 0
|| strlen($client->client_secret) == 0)
die('Please go to LinkedIn Apps page https://www.linkedin.com/secure/developer?newapp= , '.
'create an application, and in the line '.$application_line.
' set the client_id to Consumer key and client_secret with Consumer secret. '.
'The Callback URL must be '.$client->redirect_uri).' Make sure you enable the '.
'necessary permissions to execute the API calls your application needs.';
if (($success = $client->Initialize()))
{
if (($success = $client->Process()))
{
if (strlen($client->access_token))
{
$parameters = new stdClass;
$parameters->comment = "test";
$parameters->content = new stdClass;
$parameters->content->title = "A title for your share";
$parameters->content->{'submitted-url'} = "http://www.linkedin.com";
$parameters->content->{'submitted-image-url'} = "http://filedmysitehomewizhtml.altervista.org/lavori/b/immagini/1.jpg";
$parameters->visibility = new stdClass;
$parameters->visibility->code = 'anyone';
$success = $client->CallAPI(
'http://api.linkedin.com/v1/people/~/shares',
'POST', $parameters, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user);
}
}
$success = $client->Finalize($success);
}
if($client->exit)
exit;
if(strlen($client->authorization_error))
{
$client->error = $client->authorization_error;
$success = false;
}
if($success)
{
}
Matteo Lerone - 2017-03-06 07:34:22 - In reply to message 51 from Matteo Lerone
Sorry, no problem, I have solved.
Manuel Lemos - 2017-03-06 10:59:15 - In reply to message 51 from Matteo Lerone
The request is correct but the LinkedIn API URL must use https.
api.linkedin.com/v1/people/~/shares
Also the application must have the redirect_uri set to https.
You also need to have w_share scope enabled in the application.
omega1 - 2018-04-23 18:59:49 - In reply to message 51 from Matteo Lerone
Using the following snippet of code, how could I post on behalf of the page, rather than myself (page admin).
Is that possible? If so, what would I need to modify from the below code?
Thank you.
if(($success = $client->Initialize()))
{
if(($success = $client->Process()))
{
if(strlen($client->access_token))
{
$success = $client->CallAPI(
'https://api.linkedin.com/v1/people/~',
'GET', array(
'format'=>'json'
), array('FailOnAccessError'=>true), $user);
$parameters = new stdClass;
$parameters->comment = "Testing";
$parameters->content = new stdClass;
$parameters->content->title = "Testing";
$parameters->content->{'submitted-url'} = "https://";
$parameters->content->{'submitted-image-url'} = "https://image.png";
$parameters->visibility = new stdClass;
$parameters->visibility->code = 'anyone';
$success = $client->CallAPI(
'http://api.linkedin.com/v1/people/~/shares',
'POST', $parameters, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user);
}
}
$success = $client->Finalize($success);
}
|