elninotech/linkedin-api-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

elninotech/linkedin-api-client

Composer 安装命令:

composer require elninotech/linkedin-api-client

包简介

LinkedIn API client. Handles OAuth, CSRF protection. Easy to implement and extend. This is a standalone library for any composer project.

README 文档

README

CI Status codecov Latest Stable Version Total Downloads

A PHP library to handle authentication and communication with LinkedIn API. The library/SDK helps you to get an access token and when authenticated it helps you to send API requests. You will not get everything for free though... You have to read the LinkedIn documentation to understand how you should query the API.

To get an overview what this library actually is doing for you. Take a look at the authentication page from the API docs.

Features

Here is a list of features that might convince you to choose this LinkedIn client over some of our competitors'.

  • Flexible and easy to extend
  • Developed with modern PHP standards
  • Not developed for a specific framework.
  • Handles the authentication process
  • Respects the CSRF protection

Installation

First, install Linkedin-API-client via the Composer package manager:

composer require elninotech/linkedin-api-client

Ensure that the php-http/discovery composer plugin is allowed to run or install a client manually if your project does not already have a PSR-18 client integrated.

composer require guzzlehttp/guzzle

If you are updating from a previous version, make sure to read the upgrade documentation.

Usage

In order to use this API client (or any other LinkedIn clients), you have to register your application with LinkedIn to receive an API key. Once you've registered your LinkedIn app, you will be provided with an API Key and Secret Key.

LinkedIn login

This example below is showing how to login with LinkedIn.

<?php

/**
 * This demonstrates how to authenticate with LinkedIn and send api requests
 */

/*
 * First you need to make sure you've used composers auto load. You have is probably 
 * already done this before. You usually don't bother..
 */
//require_once "vendor/autoload.php";

$linkedIn = new Elnino\LinkedIn\LinkedIn('client_id', 'client_secret');

if ($linkedIn->isAuthenticated()) {
    //we know that the user is authenticated now. Start query the API
    $user=$linkedIn->get('/v2/me/?projection=(id,firstName,lastName)');
    echo "Welcome ".$user['firstName'];

    exit();
} elseif ($linkedIn->hasError()) {
    echo "User canceled the login.";
    exit();
}

//if not authenticated
$url = $linkedIn->getLoginUrl();
echo "<a href='$url'>Login with LinkedIn</a>";

How to post on LinkedIn wall

The example below shows how you can post on a users wall. The access token is fetched from the database.

$linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
$linkedIn->setAccessToken('access_token_from_db');

$options = array('json'=>
    array(
        'commentary' => 'Im testing the El Niño LinkedIn client! https://github.com/elninotech/Linkedin-API-client',
        'visibility' => array(
            'code' => 'anyone'
        )
    )
);

$result = $linkedIn->post('rest/posts', $options);

var_dump($result);

// Prints: 
// array (size=2)
//   'updateKey' => string 'UPDATE-01234567-0123456789012345678' (length=35)
//   'updateUrl' => string 'https://www.linkedin.com/updates?discuss=&scope=01234567&stype=M&topic=0123456789012345678&type=U&a=mVKU' (length=104)

Configuration

The api options

The third parameter of LinkedIn::api is an array with options. Below is a table of array keys that you may use.

Option name Description
body The body of a HTTP request. Put your json string here.
headers This is HTTP headers to the request
json This is an array with json data that will be encoded to a json string.
response_data_type To override the response format for one request
query This is an array with query parameters

Understanding response data type

The data type returned from LinkedIn::api can be configured. You may use the third constructor argument, the LinkedIn::setResponseDataType or as an option for LinkedIn::api

// By constructor argument
$linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret', 'array');

// By setter
$linkedIn->setResponseDataType('string');

// Set format for just one request
$linkedIn->get('/v2/me/?projection=(id,firstName,lastName)', array('response_data_type'=>'psr7'));

Below is a table that specifies what the possible return data types are when you call LinkedIn::api.

Type Description
array An assosiative array. This can only be used with the json format.
psr7 A PSR7 response.
stream A file stream.
string A plain old string.

Use different Session classes

You might want to use another storage than the default SessionStorage. If you are using Laravel you are more likely to inject the IlluminateSessionStorage.

$linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
$linkedIn->setStorage(new IlluminateSessionStorage());

You can inject any class implementing DataStorageInterface. You can also inject different UrlGenerator classes.

Using different scopes

If you want to define special scopes when you authenticate the user you should specify them when you are generating the login url. If you don't specify scopes LinkedIn will use the default scopes that you have configured for the app.

$scope = 'r_fullprofile,r_emailaddress,w_share';
//or 
$scope = array('rw_groups', 'r_contactinfo', 'r_fullprofile', 'w_messages');

$url = $linkedIn->getLoginUrl(array('scope'=>$scope));
echo "<a href='$url'>Login with LinkedIn</a>";

Using a different http client

If you want to customize how the requests are being sent, you can inject a different RequestManager when instantiating the API.

$myRequestManager = new MySpecialRequestManager();
$linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret', 'array', $myRequestManager);

Special thanks

This repo was originally created by Thomas Nyholm from Happyr.

elninotech/linkedin-api-client 适用场景与选型建议

elninotech/linkedin-api-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「client」 「oauth」 「sdk」 「linkedin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 elninotech/linkedin-api-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 elninotech/linkedin-api-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 elninotech/linkedin-api-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 68
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 31
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 94
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-22