ashwinks / php-linkedin-sdk Goto Github PK
View Code? Open in Web Editor NEWA PHP wrapper for the LinkedIn API
A PHP wrapper for the LinkedIn API
Hi, I am using code like this and getting class not found error.
I already checked if the file is included correctly or not using get_included_files()
, still this is happening.
Where I'm going wrong??
<?php
include 'lib/LinkedIn/LinkedIn.php';
print_r(get_included_files());
$li = new LinkedIn(
array(
'api_key' => 'myapikey',
'api_secret' => 'myapisecret',
'callback_url' => 'https://mydomain.com/redirecthere'
)
);
?>
I initiate the class as stated in the readme file like
$li = new LinkedIn(
array(
'api_key' => 'yourapikey',
'api_secret' => 'yourapisecret',
'callback_url' => 'https://yourdomain.com/redirecthere'
)
);
$url = $li->getLoginUrl
(
array(
LinkedIn::SCOPE_BASIC_PROFILE,
LinkedIn::SCOPE_EMAIL_ADDRESS,
LinkedIn::SCOPE_NETWORK
)
);
$token = $li->getAccessToken($_REQUEST['code']);
the getAccessToken function gives a 500 error.
When I print out the contents of $li, it says "_access_token:LinkedIn\LinkedIn:private".
Am I missing something?
SCOPE_READ_WRTIE_UPDATES
(line 22 of LinkedIn.php)
I'm confused as to why the getAccessCode($authorization_code)
method always has to return a previously existing access code if one exists. It seems to me that if you specify an authorization code, it should request a new access token using that code regardless of whether or not the API has had an access token set.
I'm saving my access token, but of course I will have to request a new one periodically before it expires. I'd like to be able to do this without having to worry about whether or not I can set the access token beforehand (I have another custom class that is using the LI API and it tells the api to use the access token it has saved as soon as it instantiates).
The constant declarem in line 22, Linkedin\Linkedin::SCOPE_READ_WRTIE_UPDATES
the should be SCOPE_READ_WRITE_UPDATES
A recent pull request has added the following line to the ->fetch() method
$headers[] = 'Authorization: Bearer ' . $this->getAccessToken();
This is now causing the LinkedIn API to error with the message "Mutiple authentication schemes detected" [sic] as the token is included both in a header and on the query string.
Thanks for this library! Easy to setup and has worked as expected up until now. Attempting to post to a share to linkedin but getting back:
Request Error: Can not parse JSON share document.
Request body:
Error:
null. Raw Response: Array
(
[errorCode] => 0
[message] => Can not parse JSON share document.
Request body:
Error:
null
[requestId] => *********
[status] => 400
[timestamp] => 1389818941824
)
seems that i may be formatting the json payload incorrectly, but as far as i can tell (the documentation on their json formatting is sparse) this should be correct
$linkedin->post('people/~/shares', array("comment"=>"This is a cool comment"));
The other thing i noticed while reading their documentation is that requests require a 'Content-Type: application/json' header. I can see that you have included the 'x-li-format: json' header but see no content type header. perhaps this is the problem?
Thanks again
Hi,
Since last week, I'm getting the following errors on authentication:
invalid_request -- missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired
It was working fine. Any changes in the API endpoints?
Thanks,
Hey,
Can you please Update your library to latest version of LinkedIn Api
after generation token and token expires save in database. Then makes new file and call api post for share but can't work in another file. It is work only same call back url file. I needs to new file in post.
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"}}
)
Allot of users are having trouble with the LinkedIn API.
A LinkedIn employee has responded to the issue:
https://developer.linkedin.com/comment/28938#comment-28938
Data must be posted as query parameters.
Do you think you can update this in your class?
Thanks!
At https://github.com/ashwinks/PHP-LinkedIn-SDK/blob/master/LinkedIn/LinkedIn.php#L241 the method call has no param and so at https://github.com/ashwinks/PHP-LinkedIn-SDK/blob/master/LinkedIn/LinkedIn.php#L95 the $authorization_code never gets a value and so it can't function.
It would be great if you can register this package at https://packagist.org/ so we can pull it in using Composer ๐
First of all great work! Somehow I can't get Share API to work with this.
I tried multiple parameter types and I always get this.
[errorCode] => 0
[message] => Invalid xml {Expected elements 'post-network-update@http://api.linkedin.com/v1 id@http://api.linkedin.com/v1 visibility@http://api.linkedin.com/v1 ad-account@http://api.linkedin.com/v1 comment@http://api.linkedin.com/v1 attribution@http://api.linkedin.com/v1 mention@http://api.linkedin.com/v1 private-message@http://api.linkedin.com/v1 share-target-reach@http://api.linkedin.com/v1' instead of 'visibilty@http://api.linkedin.com/v1' here in element share@http://api.linkedin.com/v1}
[requestId] => NC50O2WKV9
[status] => 400
[timestamp] => 1397323889255
This is how I set my $payload when doing a post request with php $this->LinkedIn->post($endpoint, $payload);
Array
(
[comment] => 20+ Awesome Ways to Get More Followers for Your Google Plus Business Page - http://blog.kissmetrics.com/get-more-google-plus-followers/
[content] => Array
(
[submitted-url] => http://blog.kissmetrics.com/get-more-google-plus-followers/
[title] => Test
)
[visibilty] => Array
(
[code] => anyone
)
)
The problem is not with auth. token, since I never get an error around that and I have pre-called php $this->LinkedIn->setAccessToken($creds['token']);
.
Any guess on what it could be, is my $payload structured wrong? I gone over and over through Linkedins Share API docs, but I just don't see anything I could miss.
Thanks
please help me
Nice class,
at this far the authorisation went well.
So now I can get long-lived access_token for my webapp users and store these.
So next I'm trying to get my first post (acting as one of my users)
'cause there is little documentation, I try this, but getting:
Mutiple authentication schemes detected
Any help out there? TIA!!
cheers
Harry
$li = new LinkedIn(
array(
'api_key' => '_',
'api_secret' => '_**',
'callback_url' => 'http://mydomain.nl/socnet.php'
)
);
$li->setAccessToken($storedusertoken);
$post = array(
'comment' => 'Test social Share',
'content' => array(
'title' => 'Test Title',
'description' => 'test description', //Maxlen(255)
'submitted_url' => 'http://tinyurl.com/z44rtdzo3f'
),
'visibility' => array(
'code' => 'anyone'
));
$post = $li->post('people/~/shares', $post);
$post = $li->post('people/~/shares', $post);
Hello,
is it possible to get a better ExceptionHandling? The class only returns a RuntimeException. And the message is an array parsed into a string.
protected 'message' => string 'Request Error: Invalid access token.. Raw Response: Array
(
[errorCode] => 0
[message] => Invalid access token.
[requestId] => EZFSEK5QV1
[status] => 401
[timestamp] => 1424704122777
)
I mean, I could simplye RegEx the status to get a better status code, but this doesn't seem good practice. I like the class so far, however, reacting to errors is not satisfying.
I'm getting the error invalid access token.
Here's more info: In response to the authorization I am told https://lifeboat.com/linkedin.post/?code=AQRS2NUSZAXDOX6pAaX5NAGxzm4rBqIpL95G-c31XRq9YULeeZ55TxTzb5IsBGj3Jt7SJNG2bIZj7x8zQdyRVxWMbhMPJBjflhWXM3OGQWNAVG28-rA&state=552e31c1156d94.09928605
So I set my authorization code to AQRS2NUSZAXDOX6pAaX5NAGxzm4rBqIpL95G-c31XRq9YULeeZ55TxTzb5IsBGj3Jt7SJNG2bIZj7x8zQdyRVxWMbhMPJBjflhWXM3OGQWNAVG28-rA and try
$token = $li->getAccessToken();
print "Token is $token\n";
$info = $li->get('/people/~:(first-name,last-name,positions)');
And get:
Token is AQRS2NUSZAXDOX6pAaX5NAGxzm4rBqIpL95G-c31XRq9YULeeZ55TxTzb5IsBGj3Jt7SJNG2bIZj7x8zQdyRVxWMbhMPJBjflhWXM3OGQWNAVG28-rA
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Request Error: Invalid access token.. Raw Response: Array
(
[errorCode] => 0
[message] => Invalid access token.
[requestId] => B7DCHS9W2U
[status] => 401
[timestamp] => 1429091044022
)
' in /u/home/lifeboat/linkedin.post.php:364
Hey,
I'm having problem with using this library at all,
I basicly just added this at start:
include 'LinkedIn.php';
$li = new LinkedIn\LinkedIn(
array(
'api_key' => 'api_KEY',
'api_secret' => 'API_SECRETone',
'callback_url' => 'http://localhost/xampp/linkedin/'
)
);
which throw now error, but as soon as I try do something else like:
$token = $li->getAccessToken($_REQUEST['code']);
Error dispaly: Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Invalid authorization code. Pass in the "code" parameter from your callback url' in
As per the instructions, I included the LinkedIn class and then in my file created the LinkedIn object and then set the URL with
Love the wrapper, worked well for me.
However, I had to manually add rw_company_admin to the SCOPE_ constants to be able to post to a Company page. Perhaps you want to add it in the master? And companyId to the $_config array?
It has been over two years since the last release and there have been some update to this project (new scopes in particular to my interest). Can you generate a new release so that these changes can be grabbed via composer with out resorting to using the dev-master?
Hi.
Are there any tutorials or examples on how to use this library? I've got it working so far as calling:
$linkedin -> fetch('/people/~/group-memberships');
but this only returns 10 groups. I'm guessing I add count = X to the payload parameter but that's just throwing an error.
Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.