mezon/social-network

https://github.com/alexdodonov/mezon-social-network

1.1.1 2022-01-18 16:06 UTC

This package is auto-updated.

Last update: 2024-09-18 21:40:18 UTC


README

Build Status codecov Scrutinizer Code Quality

安装

只需输入

composer require mezon/social-network

所有支持的社交网络

  • Facebook
  • VKontakte
  • Odnoklassniki

如果您需要支持列表中未列出的社交媒体,请使用 问题创建表单

Facebook认证代码

首先,我们需要创建 Facebook应用

之后,您就可以在您的网站登录页面使用这个应用。

然后在您的代码中创建对象

$facebook = new \Mezon\SocialNetwork\Auth\Facebook([
	'client_id' => 'client id from the Facebook application',
	'client_secret' => 'client secret from the Facebook application',
	'redirect_uri' => 'URI of your web application on wih user will be redirected after authorization on Facebook'
]);

然后在您的页面上输出一个按钮,允许用户使用Facebook账号在您的网站上登录

print('<a href="'.$facebook->getLink().'"Sign In</a>a>');

点击该链接后,用户将被重定向到Facebook。在那里,他们将确认他们想使用您的应用进行登录,并授予访问其账户数据的权限。然后他们将被重定向到您在Facebook上创建应用时指定的'redirect_uri',在设置$facebook对象时必须使用相同的URL。

// your redirect_uri must process code

if($facebook->auth($_GET['code'])) {
	// authorization was successfull
}
else {
	// an error have occured
}

如果$facebook->auth()方法返回true,则表示一切正常,您可以获取用户数据

var_dump($facebook->userInfo);
// here:
// [
//	'id' => 'user id',
//	'first_name' => 'user first name',
//	'last_name' => 'user last name',
//	'email' => 'user email, but looks like Facebook has forbidden to fetch this info, so dont rely on this field',
//	'picture' => 'user avatar'
// ]

了解更多信息

更多信息可以在以下链接找到

Twitter

dev.to

Slack