FaceBook登录,从code到获得access token
文档来源:https://developers.facebook.com/docs/marketing-apis/overview/authentication/
在FB的开发者后台配置好回调地址(Valid OAuth Redirect URIs):https://iwangtao.com/oauth2/meta/auth
然后下面网址,使用FB账号授权。v13.0是当前API接口版本。redirect_uri是配置的回调地址,FB用户授权之后,会把code传到这个网址。scope是授权的范围,这里的ads_read是查看FB广告权限;
https://www.facebook.com/v13.0/dialog/oauth?client_id={你的App ID}&redirect_uri=https://iwangtao.com/oauth2/meta/auth&scope=ads_read
授权之后,然后跳转到https://iwangtao.com/oauth2/meta/auth?code={code}#_=_
拿到code后,在服务器端使用GET方法请求下面接口。redirect_uri是后面配置的回调地址;app_secret是appid对应的app secret。
https://graph.facebook.com/v13.0/oauth/access_token?client_id={你的App ID}&client_secret={app_secret}&redirect_uri={redirect_uri}&code={code}
如果一切正常,就可以拿到access_token的JSON信息了
{
"access_token": "********",
"token_type": "bearer",
"expires_in": 5174633
}