100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > php实现抖音开放平台账号授权获取码code 获取access_token

php实现抖音开放平台账号授权获取码code 获取access_token

时间:2023-08-04 05:42:59

相关推荐

php实现抖音开放平台账号授权获取码code 获取access_token

直接上代码

public function index(){$code = $_GET['code'];$dyClientKey = xxx;$dyClientSecret = xxx;if(empty($code)){$redirect_uri = "";//授权回调域名(要和在抖音平台申请的网站应用回调域名要一致) 用来接收抖音平台返回的code$redirect_uri = urlencode($redirect_uri);$url = "/platform/oauth/connect/?client_key={$dyClientKey}&response_type=code&scope=user_info,video.create&redirect_uri={$redirect_uri}";header("Location:" . $url);}else{$get_access_token_url = "/oauth/access_token?client_key={$dyClientKey}&client_secret={$dyClientSecret}&grant_type=authorization_code&code={$code}";$access_token_info = $this->getJson($get_access_token_url);echo '<pre>';var_dump($access_token_info);}}//curl请求public function getJson($url){$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);curl_setopt($ch, CURLOPT_HEADER, FALSE);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);//为true,则会跟踪爬取重定向页面,否则,不会跟踪重定向页面$output = curl_exec($ch);curl_close($ch);return json_decode($output, true);}

返回access_token信息截图

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。