关于php实现抖音开放平台账号授权获取码code、获取access_token以下文字资料是由3搜网小编为大家搜集整理后发布的内容,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“php实现抖音开放平台账号授权获取码code、获取access_token”文章吧。
直接上代码
php">public function index(){ $code = $_GET['code']; $dyClientKey = xxx; $dyClientSecret = xxx; if(empty($code)){ $redirect_uri = "http://www.xxx.com";//授权回调域名(要和在抖音平台申请的网站应用回调域名要一致) 用来接收抖音平台返回的code $redirect_uri = urlencode($redirect_uri); $url = "https://open.douyin.com/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 = "https://open.douyin.com/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信息
以上就是关于“php实现抖音开放平台账号授权获取码code、获取access_token”这篇文章的内容,希望分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注3搜网技术频道。