bannerColor WARNING_YELLOW templateName stackForums

oAuth process for linkedin using php

44 posts / 0 new
Last post
Ziya Rahman's picture
Joined: 2009-11-23
Nov 25, 2009
oAuth process for linkedin using php

Hi,Friends any one help me about php oAuth process for linkedin for getting loggedin user profile.Thanks in advanceZiyaNowI have fetched linkedin user's profile......to get code.......please see....http://developer.linkedin.com/thread/1222

Joined: 2009-11-24
Nov 25, 2009
- -
Joined: 2009-11-23
Nov 26, 2009
Anonymous (not verified)
Nov 26, 2009
Ziya Rahman's picture
Joined: 2009-11-23
Nov 26, 2009

Hi Winfred,Thakns for replying me..I have downloaded zip filei got message --- You should install PECL lib OAuthHow we can install ----- install PECL lib OAuthThanksZiya

Anonymous (not verified)
Nov 26, 2009

Thats more or less depending on the OS you are running on. For linux you can use "pecl install oauth-beta"  This will install the library, but the last step is to copy the generated oauth.so file to your extension directory of php and add this to your php.ini.You can also just download de library from http://pecl.php.net/package/oauth and install from command line.For further information for installing a pecl library please go to : http://nl.php.net/manual/en/install.pecl.phpw

Ziya Rahman's picture
Joined: 2009-11-23
Nov 27, 2009

Hi Winfred,Thakns for replying me..I am working on it, as per your description.ThanksZiya

Vincent Barberot's picture
Joined: 2009-11-24
Nov 27, 2009

Hi Winfred,By doing 'pecl install oauth-beta', I have :debian:/# pecl install oauth-betaWARNING: channel "pecl.php.net" has updated its protocols, use "channel-update pecl.php.net" to updatedownloading oauth-0.99.9.tgz ...Starting to download oauth-0.99.9.tgz (25,609 bytes).........done: 25,609 bytes4 source files, buildingrunning: phpizesh: phpize: command not foundERROR: `phpize' failedI wanted to use "channel-update pecl.php.net" by command line, nevertheless it's out. Hoiw can I resolve the problem, please ?Thanks by advance,Best Regards,Vincent.

Anonymous (not verified)
Nov 27, 2009

this is probably becuase the php-devel package is not installed. your problem is that phpize isn't found. here you find the answer.http://nirlevy.blogspot.com/2008/01/phpize-command-not-found.htmltry running: yum install php-develw

Vincent Barberot's picture
Joined: 2009-11-24
Nov 27, 2009

The response is :debian:/# yum install php-develSetting up Install ProcessParsing package install argumentsNo package php-devel available.Nothing to doHow can I do now ? I don't understand. Do you have others solutions ?Thanks by advance,Vincent.

Anonymous (not verified)
Nov 27, 2009

On what version of php are you running?w

Vincent Barberot's picture
Joined: 2009-11-24
Nov 27, 2009

I use PHP5

Anonymous (not verified)
Nov 27, 2009

Isn't there somebody you know that could look at the php5 installation and make the php-dev function work. My way should be google till i found some sollution.w

Vincent Barberot's picture
Joined: 2009-11-24
Nov 27, 2009

'pecl install oauth-beta' is running, nevertheless I have errors. It's the first time that I do this.debian:/# pecl install oauth-betadownloading oauth-0.99.9.tgz ...Starting to download oauth-0.99.9.tgz (25,609 bytes).....done: 25,609 bytes4 source files, buildingrunning: phpizeConfiguring for:PHP Api Version:         20041225Zend Module Api No:      20060613Zend Extension Api No:   220060519building in /var/tmp/pear-build-root/oauth-0.99.9running: /tmp/pear/temp/oauth/configurechecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking for a sed that does not truncate output... /bin/sedchecking for gcc... gccchecking for C compiler default output file name... a.outchecking whether the C compiler works... yeschecking whether we are cross compiling... nochecking for suffix of executables...checking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking whether gcc and cc understand -c and -o together... yeschecking for system library directory... libchecking if compiler supports -R... nochecking if compiler supports -Wl,-rpath,... yeschecking build system type... i686-pc-linux-gnuchecking host system type... i686-pc-linux-gnuchecking target system type... i686-pc-linux-gnuchecking for PHP prefix... /usrchecking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64checking for PHP extension directory... /usr/lib/php5/20060613+lfschecking for PHP installed headers prefix... /usr/include/php5checking for re2c... noconfigure: WARNING: You will need re2c 0.12.0 or later if you want to regenerate PHP parsers.checking for gawk... nochecking for nawk... nawkchecking if nawk is broken... nochecking for oauth support... yes, sharedchecking for ld used by gcc... /usr/bin/ldchecking if the linker (/usr/bin/ld) is GNU ld... yeschecking for /usr/bin/ld option to reload object files... -rchecking for BSD-compatible nm... /usr/bin/nm -Bchecking whether ln -s works... yeschecking how to recognize dependent libraries... pass_allchecking how to run the C preprocessor... gcc -Echecking for ANSI C header files... yeschecking for sys/types.h... yeschecking for sys/stat.h... yeschecking for stdlib.h... yeschecking for string.h... yeschecking for memory.h... yeschecking for strings.h... yeschecking for inttypes.h... yeschecking for stdint.h... yeschecking for unistd.h... yeschecking dlfcn.h usability... yeschecking dlfcn.h presence... yeschecking for dlfcn.h... yeschecking for g77... nochecking for xlf... nochecking for f77... nochecking for frt... nochecking for pgf77... nochecking for cf77... nochecking for fort77... nochecking for fl32... nochecking for af77... nochecking for xlf90... nochecking for f90... nochecking for pgf90... nochecking for pghpf... nochecking for epcf90... nochecking for gfortran... nochecking for g95... nochecking for xlf95... nochecking for f95... nochecking for fort... nochecking for ifort... nochecking for ifc... nochecking for efc... nochecking for pgf95... nochecking for lf95... nochecking for ftn... nochecking whether we are using the GNU Fortran 77 compiler... nochecking whether  accepts -g... nochecking the maximum length of command line arguments... 98304checking command to parse /usr/bin/nm -B output from gcc object... okchecking for objdir... .libschecking for ar... archecking for ranlib... ranlibchecking for strip... stripchecking if gcc supports -fno-rtti -fno-exceptions... nochecking for gcc option to produce PIC... -fPICchecking if gcc PIC flag -fPIC works... yeschecking if gcc static flag -static works... yeschecking if gcc supports -c -o file.o... yeschecking whether the gcc linker (/usr/bin/ld) supports shared libraries... yeschecking whether -lc should be explicitly linked in... nochecking dynamic linker characteristics... GNU/Linux ld.sochecking how to hardcode library paths into programs... immediatechecking whether stripping libraries is possible... yeschecking if libtool supports shared libraries... yeschecking whether to build shared libraries... yeschecking whether to build static libraries... noconfigure: creating libtoolappending configuration tag "CXX" to libtoolappending configuration tag "F77" to libtoolconfigure: creating ./config.statusconfig.status: creating config.hrunning: make/bin/sh /var/tmp/pear-build-root/oauth-0.99.9/libtool --mode=compile gcc  -I. -I/tmp/pear/temp/oauth -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oauth-0.99.9/include -I/var/tmp/pear-build-root/oauth-0.99.9/main -I/tmp/pear/temp/oauth -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -DHAVE_CONFIG_H  -g -O2 -Wall -g   -c /tmp/pear/temp/oauth/oauth.c -o oauth.lomkdir .libs gcc -I. -I/tmp/pear/temp/oauth -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oauth-0.99.9/include -I/var/tmp/pear-build-root/oauth-0.99.9/main -I/tmp/pear/temp/oauth -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -Wall -g -c /tmp/pear/temp/oauth/oauth.c  -fPIC -DPIC -o .libs/oauth.o/tmp/pear/temp/oauth/oauth.c:45:23: error: curl/curl.h: Aucun fichier ou répertoire de ce typeIn file included from /tmp/pear/temp/oauth/oauth.c:47:/tmp/pear/temp/oauth/php_oauth.h:144: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âmake_reqâ/tmp/pear/temp/oauth/oauth.c:601: error: expected â)â before â*â token/tmp/pear/temp/oauth/oauth.c:763: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âmake_reqâ/tmp/pear/temp/oauth/oauth.c: In function âoauth_fetchâ:/tmp/pear/temp/oauth/oauth.c:1166: warning: implicit declaration of function âmake_reqâ/tmp/pear/temp/oauth/oauth.c: In function âzm_startup_oauthâ:/tmp/pear/temp/oauth/oauth.c:2047: warning: implicit declaration of function âcurl_global_initâ/tmp/pear/temp/oauth/oauth.c:2047: error: âCURL_GLOBAL_DEFAULTâ undeclared (first use in this function)/tmp/pear/temp/oauth/oauth.c:2047: error: (Each undeclared identifier is reported only once/tmp/pear/temp/oauth/oauth.c:2047: error: for each function it appears in.)/tmp/pear/temp/oauth/oauth.c:2047: error: âCURLE_OKâ undeclared (first use in this function)/tmp/pear/temp/oauth/oauth.c: In function âzm_shutdown_oauthâ:/tmp/pear/temp/oauth/oauth.c:2092: warning: implicit declaration of function âcurl_global_cleanupâmake: *** [oauth.lo] Erreur 1ERROR: `make' failedI think I forget to do something but I don't know. My example API Linkedin ask me always 'You should install PECL lib OAuth'

Jeroen Sentel's picture
Joined: 2009-11-26
Nov 29, 2009

I ran into the same problem.solution (for me) was to install libcurl4-dev-openssl and then channel://pecl.php.net/oauth-0.99.9 install worked fine...The next thing I ran into was a problem with the CA certificates (!?)Uncaught exception 'OAuthException' with message 'making the request failed (Problem with the SSL CA cert (path? access rights?))'Solved this by adding $oauth->disableSSLChecks(); just before requestToken.As soon as I have everything up and running I'll share this.edit: Using the example from linkedphp.com everything worked fine and I succesfully fetched my LinkedIn profile.

Anonymous (not verified)
Nov 29, 2009

Thanks for the suggestionI will add it to the codew

Vincent Barberot's picture
Joined: 2009-11-24
Nov 29, 2009

GREAT !Thank you very much Jeroen, my example is ok. I used it in my intranet.I didn't have the problem with the CA certificates. I know the example linkedphp.com and it is ok for me, nevertheless I wanted Oauth.Now, I'm going to do several examples to be succeed my project.If I can help, it will be with pleasure. Still thank you very much.Best Regards,Vincent.

Ziya Rahman's picture
Joined: 2009-11-23
Dec 1, 2009

Hi Vincent ,I want to import linkedin user's profile with zend framework.Please reply me if possible.ThanksZiya

Vincent Barberot's picture
Joined: 2009-11-24
Dec 1, 2009

Hi,So you use PHP, you will find all the responses in another thread, here http://developer.linkedin.com/thread/1153?tstart=0Best Regards,Vincent.

Jeroen Sentel's picture
Joined: 2009-11-26
Dec 1, 2009
George Carter's picture
Joined: 2009-12-06
Dec 6, 2009

I'm stumped. I'm doing PHP development on a Windows XP PC and want to install the Pecl Oauth code to experiment with the Linkedin API.I have downloaded the tgz file from http://pecl.php.net/package/oauth, and uncompressed it. But I don't know what to do next so I can refer to it in my applications.Thanks,George

Ziya Rahman's picture
Joined: 2009-11-23
Dec 6, 2009

Hi George,If you will get success to install Pecl Oauth, its gr8.You can also try below stuff to communicate linkedinhttp://developer.linkedin.com/thread/1222?tstart=0ThanksZiya

George Carter's picture
Joined: 2009-12-06
Dec 7, 2009

Hi Ziya,Thanks for the response. I took a look at your zip file and noticed it includes OAuth.php. Where did you get that file?Thanks,George

Ziya Rahman's picture
Joined: 2009-11-23
Dec 7, 2009

Hi George,I took from....http://oauth.googlecode.com/svn/code/php/OAuth.phpThanksZiya

Anylinux Work
Joined: 2009-12-09
Dec 9, 2009

Hi intercom,Thanks for gr8 workThanksZiya

George Carter's picture
Joined: 2009-12-06
Dec 10, 2009

Thanks. I think this is what I need.George

Ziya Rahman's picture
Joined: 2009-11-23
Dec 10, 2009

Glad to help George !Ziya

John Tegen's picture
Joined: 2009-11-23
Dec 17, 2009

"intercom":Looks like you are using the same Google OAuth PHP library as we are.  We have hit a roadblock with POSTing to LinkedIn with this library.  Have you used that part of LinkedIn yet and had success with the POST command?  If so, do you have any code snippets or modification to the OAuth Google PHP library that got this to work?  My forehead is getting soar from hitting it against the wall.Much appreciated,John

Ziya Rahman's picture
Joined: 2009-11-23
Dec 17, 2009

Sorry John,I didn't used this library with post.Ziya

Zhoulan Kablog's picture
Joined: 2009-12-28
Dec 28, 2009

Hi John,I am using the same Google OAuth PHP library as you do (http://oauth.googlecode.com/svn/code/php/OAuth.php). I notice that you have some awesome posts about utilizing that libary with a few modifications. However, with the changes you mentioned, I am only able to sucessfully make GET and PUT requests, but still getting 401 errors for POST requests with response like: [unauthorized]. OAU:-uaHLIRQrmz7PyzOZtR0FGF97UsQu-XnTqJZGt3d1LOX_-4ZFDuYYnvWxtdKlLCE|7dda9d86-e0f5-4d8a-9650-5343f0be066|*01|*01:1262044478:9pHLvg0C7pU877Lg2Ko9CKHTsOcI would really appreciate if you can shed some light on how to work with POST requests. For your reference, here is the base string for oauth signature, as well as the header info for one of my post-comment requests:POST&https%3A%2F%2Fapi.linkedin.com%2Fv1%2Fpeople%2F~%2Fnetwork%2Fupdates%2Fkey%3DSTAT-27952421-8-%2A1%2Fupdate-comments&oauth_consumer_key%3D-uaHLIRQrmz7PyzOZtR0FGF97UsQu-XnTqJZGt3d1LOX_-4ZFDuYYnvWxtdKlLCE%26oauth_nonce%3D1262a05150a94e8684d2bb5eb03a1102%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1262044478%26oauth_token%3D7dda9d86-e0f5-4d8a-9650-5343f0be0661%26oauth_version%3D1.0Authorization: OAuth realm="http://api.linkedin.com/",Content-Type= "text/xml",oauth_version="1.0",oauth_nonce="1262a05150a94e8684d2bb5eb03a1102",oauth_timestamp="1262044478",oauth_consumer_key="-uaHLIRQrmz7PyzOZtR0FGF97UsQu-XnTqJZGt3d1LOX_-4ZFDuYYnvWxtdKlLCE",oauth_token="7dda9d86-e0f5-4d8a-9650-5343f0be0661",oauth_signature_method="HMAC-SHA1",oauth_signature="9pHLvg0C7pU877Lg2Ko9CKHTsOc%3D"Thanks again!-zhoulan

John Tegen's picture
Joined: 2009-11-23
Dec 29, 2009

The main thing with POST is to set the headers correctly.  Sample below if from our proxy PHP code between Flex and LinkedIn:  $app_key      = CRM_LINKEDIN_API_KEY;  $app_secret   = CRM_LINKEDIN_SECRET_KEY;  $host = "http://api.linkedin.com";  $uri    = osf_post( 'uri' ); // function to get posted variables  $token  = osf_post( 'token' ); // saved authorized user account  $secret = osf_post( 'secret' ); // saved authorized user account  $method = osf_post( 'method', 'GET' );  $args   = osf_post( 'args' );  $test_consumer = new OAuthConsumer( $app_key, $app_secret, NULL );  $sig_method    = new OAuthSignatureMethod_HMAC_SHA1();  $endpoint = sprintf( "%s/%s", $host, $uri ); // need a + symbol here.  $arg_seq = array();  if( $args != "" )  {    if( $method == "GET" )    {      $values = explode( "&", $args );      $nvalues = count( $values );      for( $i=0; $i < $nvalues; $i++ )      {        if( $values[$i] != "" )        {          list( $name, $value ) = explode( "=", $values[$i] );          $arg_seq[ $name ] = str_replace( "+", " ", $value );        }      }    }  }  $req_token = new OAuthConsumer( $token, $secret, 1 );  $profile_req = OAuthRequest::from_consumer_and_token( $test_consumer, $req_token, $method,                                                        $endpoint,                                                        $arg_seq ); // but no + symbol here!  $profile_req->sign_request( $sig_method, $test_consumer, $req_token );  $headers[] = $profile_req->to_header( $host ); // modified to set realm  $ch = curl_init();  curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );  curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );  curl_setopt( $ch, CURLOPT_URL, $endpoint );  if( $method == "GET" )  {    curl_setopt( $ch, CURLOPT_HTTPGET, true );  }  else if( $method == "PUT" )  {    curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'PUT' );    curl_setopt( $ch, CURLOPT_POSTFIELDS, $args );  }  else if( $method == "POST" )  {    $headers[] = 'Content-Type: text/xml';    curl_setopt( $ch, CURLOPT_POST, TRUE );    curl_setopt( $ch, CURLOPT_POSTFIELDS, $args );  }  else if( $method == "DELETE" )  {    curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "DELETE" );  }  curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );  print curl_exec($ch);  curl_close($ch);  flush();Hope that helps

Zhoulan Kablog's picture
Joined: 2009-12-28
Dec 29, 2009

Thanks sooo much John! My code is working now

John Tegen's picture
Joined: 2009-11-23
Dec 29, 2009

Glad I could help.

Joined: 2009-12-30
Jan 6, 2010

I have read full thread. It is very useful for me..Can you tell me the arguments($args) we need to pass to update the status?Thanks.

John Tegen's picture
Joined: 2009-11-23
Jan 6, 2010

The $args is a string of name/value pairs based on the API you are trying to call.  For example:For POST commands that take the XML, $args would be the XML text.For GET commands, like get network status, the $args would be type=XXX&start=0&count=0 (or something similar)

Boon Kgim Khur's picture
Joined: 2010-11-05
Nov 9, 2010

Yo all,Just a sharing.  For those who are interested in knowing how to implement oAuth using some of the most basics PHP functions like fsockopen() without dependency on any standard OAuth library, I have posted what I found out as a step-by-step guide @ http://blog.thewebcafes.com/post/1502524959/php-step-by-step-oauth-for-dummies-based-on-linkedin.Feel free to comment there.

Adam Trachtenberg's picture
LinkedIn Employee
Joined: 2011-06-30
Nov 10, 2010

I added a comment there. I still worry about people rolling their own OAuth. It can bite you.

Paul Mennega's picture
Joined: 2009-11-30
Nov 10, 2010

On rolling our own OAuth...  there are many implementations, including PECL, Zend, some random ones on Google Code...  any chance LinkedIn is going to be releasing/blessing a particular implementation so that people can be reasonably sure that their apps will remain LinkedIn API compatible moving into the future?Paul

Adam Trachtenberg's picture
LinkedIn Employee
Joined: 2011-06-30
Nov 10, 2010

I would unofficially bless pecl/oauth. That's what I use. It works for everything I try. I will release sample code, if people want. I also like using a C extension instead of a PHP one because of performance reasons. I will look into blessing a PHP-based solution, as I know people often have times installing extensions when they don't have root on the shared host, etc.

Paul Mennega's picture
Joined: 2009-11-30
Nov 10, 2010

Ah cool, thanks Adam.  I'm hoping to modify my library in the coming weeks to work with both the pecl and the current non-pecl extension that it currently uses (it uses this to, as you mentioned, allow users to connect without having access to install extensions, etc)All the best,Paul

Boon Kgim Khur's picture
Joined: 2010-11-05
Nov 10, 2010

Hi Paul,I am looking forward to your PHP library.  It would be great if it can auto-detect for pecl/oauth installation, and use the pecl/oauth if installed, but if no, use your own built-in oauth library.Boon Kgim

Paul Mennega's picture
Joined: 2009-11-30
Nov 10, 2010

Thanks Boon!For what it's worth, the library is released, but the current version simply throw an error if PECL is installed:http://code.google.com/p/simple-linkedinphp/My library makes use of an open-source stand-alone OAuth library, which can be found here:http://oauth.googlecode.com/svn/code/php/I'll post something to the Forums when I have some progress on the future version of the library that can actually make use of the PECL extension.Paul

Boon Kgim Khur's picture
Joined: 2010-11-05
Nov 10, 2010

Hi Adam,That would be great.  One of the main reasons why I trying to develop using some of the most basic PHP functions is because not all projects I'm working on have access to installation of PECL library.  I tried using a 3rd party OAuth library from the Twitter community but apparently it has problem dealing with the XML posting (it doesn't allow me to customize headers and content mainly for "Content-Type: text/xml").I was looking for an exact replacement library for pecl/oauth in term of function interface, so that I can include it for projects that do not have pecl/oauth installed.  But it took me so much searching time that I finally decide it would be better for me to drill my head into the basic of OAuth.