Login   Register  
PHP Classes
elePHPant
Icontem

PHP OAuth class Post to user's LinkedIn Account

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP OAuth API  >  All threads  >  PHP OAuth class Post to user's LinkedIn Account  >  (Un) Subscribe thread alerts  
Subject:PHP OAuth class Post to user's LinkedIn Account
Summary:Having trouble creating the CALLAPI function correctly
Messages:50
Author:Bill Egan
Date:2012-12-13 15:48:55
Update:2014-01-08 21:28:41
 
  1 - 10   11 - 20   21 - 30   31 - 40   41 - 50  

  31. Re: PHP OAuth class Post to user's LinkedIn Account   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-10-13 06:48:05 - In reply to message 30 from david
To post shares you need to set rw_nus permissions. Did you the scope variable of the OAuth class include rw_nus in the string value? If not, that explains why the posting request was denied.

  32. Re: PHP OAuth class Post to user's LinkedIn Account   Reply   Report abuse  
Picture of Vlado Nikolchev
Vlado Nikolchev
2013-12-17 15:36:39 - In reply to message 4 from Manuel Lemos
Hello Manuel,

I use your code to post shares on behalf of my company in LinkedIn and all is good except the URLs of updates.

If you open the company page in LinkedIn (like http://www.linkedin.com/company/mycompanyname) and click on URL of the update then it's fine. The URL to our web page works. But when you open the LinkedIn front page and click on one of our company updates then the links are broken. They try to redirect you to some internal LinkedIn page, not to the external URL passed to API through the submitted-url parameter.

I pass the URLs this way:
$body->content->{'submitted-url'} = "http://ourcompanypage.com/article_id/123456";

When you open such update through the company page in LinkedIn the URL redirects to the correct URL, but if you see the update in LinkedIn front page then the URL is like:

http://www.linkedin.com/nhome/nus-redirect?url=http%3A%2F%2F ...

and it does not redirect you to http://ourcompanypage.com/article_id/123456

Please advise what might be the problem.

Cheers,
Vladimir

  33. Re: PHP OAuth class Post to user's LinkedIn Account   Reply   Report abuse  
Picture of Vlado Nikolchev
Vlado Nikolchev
2013-12-18 08:00:27 - In reply to message 31 from Manuel Lemos
Hi Manuel,

I am not absolutely sure how to pass the scope (now I just have the rw_nus permission set in my LinkedIn profile and I thought it's enough). Could you please take a look at my PHP code:

/*****************************************************/
$oauth = new OAuth($apiKey, $apiSecret); // params taken from my profile..
$oauth->setToken($accessToken, $accessTokenSecret); // params taken from my profile..

$body = new stdClass();
$body->comment = 'Some comment';
$body->content = new stdClass();
$body->content->title = 'Some title';
$body->content->description = 'Some description';
$body->content->{'submitted-url'} = 'http://www.mycompany.com/article_id/123456';
$body->visibility = new stdClass();
$body->visibility->code = 'anyone';
$body_json = json_encode($body);

$oauth->fetch('http://api.linkedin.com/v1/companies/12345678/shares', $body_json, OAUTH_HTTP_METHOD_POST, array(
"Content-Type" => "application/json",
"x-li-format" => "json"
));
$response = json_decode($oauth->getLastResponse());
/*****************************************************/

How shall I pass the scope with this code?

Notice that the code works, but links to the articles in our website are broken when opened through the LinkedIn front page. They work only if you open them through the company profile in LinkedIn.

Cheers,
Vladimir



  34. Re: PHP OAuth class Post to user's LinkedIn Account   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-12-18 08:30:10 - In reply to message 33 from Vlado Nikolchev
It does not look like you are using this OAuth class. It seems you are using somebody else's class. Are you sure you are not making some kind of confusion?

  35. Re: PHP OAuth class Post to user's LinkedIn Account   Reply   Report abuse  
Picture of Vlado Nikolchev
Vlado Nikolchev
2013-12-18 09:57:34 - In reply to message 34 from Manuel Lemos
Now I see I have really made a confusion. I am using this class http://www.php.net/manual/en/book.oauth.php
(from PECL lib).

  36. Re: PHP OAuth class Post to user's LinkedIn Account   Reply   Report abuse  
Picture of Vlado Nikolchev
Vlado Nikolchev
2013-12-18 13:31:08 - In reply to message 34 from Manuel Lemos
I know in this case it's not correct to insist anymore but if you know what I may miss please tell me. I feel like missing something very small here...

Any idea can help.

Cheers,
Vlado

  37. Re: PHP OAuth class Post to user's LinkedIn Account   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-12-18 20:19:42 - In reply to message 35 from Vlado Nikolchev
Don't bother with PECL OAuth class, it is so complicated and it does not handle the specifics of each OAuth server, that you will die before you figure out all that is wrong.

Trust me, use this OAuth API class and be happy with it.

  38. Re: PHP OAuth class Post to user's LinkedIn Account   Reply   Report abuse  
Picture of Vlado Nikolchev
Vlado Nikolchev
2013-12-19 14:20:09 - In reply to message 37 from Manuel Lemos
Hello Manuel,

I am now trying your class. Please have a look at my code. I catch no errors but it doesn't seem to publish anything in LinkedIn.

Once again: I'm trying to publish company share on behalf of my company. I am administrator of this company.

============================
$api_url = "http://api.linkedin.com/v1/companies/{id-of-my-company}/shares";

$parameters = new stdClass();
$parameters->comment = 'Some comment';
$parameters->content = new stdClass();
$parameters->content->title = 'Some title';
$parameters->content->description = 'Some description';
$parameters->content->{'submitted-url'} = 'http...';
$parameters->visibility = new stdClass();
$parameters->visibility->code = 'anyone';

$client = new oauth_client_class;
$client->debug = 1;
$client->debug_http = 1;
$client->server = 'LinkedIn';
$client->client_id = 'xxxxxxxxxxxxxxx'; // Taken from my profile
$client->client_secret = 'yyyyyyyyyyyyyyyyy'; // Taken from my profile
$client->scope = 'rw_nus';

if (($success = $client->Initialize())) {
if (($success = $client->Process())) {
if (strlen($client->access_token)) {
$success = $client->CallAPI(
$api_url, 'POST', $parameters, array(
'FailOnAccessError' => true,
'RequestContentType' => 'application/json'
)
);
}
}
$success = $client->Finalize($success);
}

if ($success) {
// ...
} else {
echo $client->error . "\n"
}
==============================

Thank you for your support.

  39. Re: PHP OAuth class Post to user's LinkedIn Account   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-12-19 21:17:52 - In reply to message 38 from Vlado Nikolchev
It is hard to tell without knowing how far have you gone in the OAuth process.

Did you enter in LinkedIn page and gave permission to access the API?

Did it return and send the API call request?

You may want to enable the debug option and look at your PHP error log file to see what happened. Do you see the companies shares HTTP request being sent to the server in the log?

  40. Re: PHP OAuth class Post to user's LinkedIn Account   Reply   Report abuse  
Picture of Vlado Nikolchev
Vlado Nikolchev
2013-12-20 12:48:34 - In reply to message 39 from Manuel Lemos
Yes, I have started it in debug mode and saw the log but I didn't know how to interpret it. As long as I see there's nothing disturbing here. Please take a look:

==================================================
OAuth client: Checking the OAuth token authorization state, referer: {our url here}
OAuth client: The OAuth access token is not set, referer: {our url here}
OAuth client: Requesting the unauthorized OAuth token, referer: {our url here}
OAuth client: Accessing the OAuth request token at https://api.linkedin.com/uas/oauth/requestToken?scope=rw_nus, referer: {our url here}
Connecting to api.linkedin.com, referer: {our url here}
Resolving HTTP server domain "api.linkedin.com"..., referer: {our url here}
Connecting to HTTP server IP 216.52.242.83 port 443..., referer: {our url here}
Connected to api.linkedin.com, referer: {our url here}
C GET /uas/oauth/requestToken?scope=rw_nus HTTP/1.1, referer: {our url here}
C Host: api.linkedin.com, referer: {our url here}
C User-Agent: PHP-OAuth-API (http://www.phpclasses.org/oauth-api $Revision: 1.74 $), referer: {our url here}
C Accept: */*, referer: {our url here}
C Authorization: OAuth oauth_consumer_key="{ckey}",oauth_nonce="{ononce}",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1387542891",oauth_version="1.0",oauth_callback="{our url..}linkedin_post_oauth_api.php",oauth_signature="{signature}", referer: {our url here}
C Connection: Keep-Alive, referer: {our url here}
C , referer: {our url here}
S HTTP/1.1 200 OK, referer: {our url here}
S Server: Apache-Coyote/1.1, referer: {our url here}
S X-LI-UUID: {UID}, referer: {our url here}
S Content-Type: text/plain, referer: {our url here}
S Content-Length: 240, referer: {our url here}
S Vary: Accept-Encoding, referer: {our url here}
S Date: Fri, 20 Dec 2013 12:34:51 GMT, referer: {our url here}
S X-Li-Fabric: PROD-ELA4, referer: {our url here}
S Connection: keep-alive, referer: {our url here}
S X-Li-Pop: PROD-ELA4, referer: {our url here}
S , referer: {our url here}
S oauth_token={token}&oauth_token_secret={secret}&oauth_callback_confirmed=true&xoauth_request_auth_url=https%3A%2F%2Fapi.linkedin.com%2Fuas%2Foauth%2Fauthorize&oauth_expires_in=599, referer: {our url here}
Keeping the connection alive to api.linkedin.com, referer: {our url here}
OAuth client: Redirecting to OAuth authorize page https://api.linkedin.com/uas/oauth/authenticate?oauth_token={token}, referer: {our url here}
OAuth client: Resetting the access token status for OAuth server located at https://api.linkedin.com/uas/oauth/accessToken, referer: {our url here}
=======================================================

 
  1 - 10   11 - 20   21 - 30   31 - 40   41 - 50