【发布时间】:2018-10-26 18:34:52
【问题描述】:
我正在使用 laravel 中的社交名流调用 LinkedIn 的 API 并得到以下响应:
Laravel\Socialite\Two\User Object
(
[token] =>
[refreshToken] =>
[expiresIn] =>
[id] =>
[nickname] =>
[name] =>
[email] => l
[avatar] =>
[user] => Array
(
[emailAddress] =>
[firstName] =>
[formattedName] =>
[headline] =>
[id] =>
[industry] =>
[lastName] =>
[location] => Array
(
[country] =>
(
[code] =>
)
[name] =>
)
[pictureUrl] =>
[positions] => Array
(
[_total] => 1
[values] => Array
(
[0] => Array
(
[company] => Array
(
[name] =>
)
[id] =>
[isCurrent] =>
[location] => Array
(
[country] => Array
(
[code] =>
[name] =>
)
[name] =>
)
[startDate] => Array
(
[month] =>
[year] =>
)
[summary] =>
[title] =>
)
)
)
[publicProfileUrl] =>
[summary] =>
[avatar_original] =>
)
然后我将回复保存到我的数据库中,但无法弄清楚如何正确访问位置、publicProfileUrl 或摘要的值。所有其他人都可以通过以下方式与社交名流一起工作:
$user = User::where('provider_id', $linkedin_user->id)->first();
if (!$user){
$user = new User;
$user->name = $linkedin_user->getName();
$user->email = $linkedin_user->getEmail();
$user->picture = $linkedin_user->getAvatar();
$user->provider_id = $linkedin_user->getId();
$user->access_token = $linkedin_user->token;
$user->save();
}
我试过添加这个:
$publicProfileUrl = array_get($linkedin_user, 'user.publicProfileUrl', null);
之后:
$user = User::where('provider_id', $linkedin_user->id)->first();
并在保存用户之前添加:
$user->linkedin = $linkedin_user[user]->publicProfileUrl;
但我很难过!
非常感谢所有帮助!
【问题讨论】:
标签: php laravel linkedin-api