實現微信小程序獲取抖音授權,使用Java實現抖音授權登錄,您需要使用抖音開放平臺提供的API
第一步 :抖音獲取授權碼
前提條件
- ?需要去官網為應用申請 scope 的使用權限。
- ?需要在本接口的 scope 傳參中填上需要用戶授權的 scope,多個 scope 以逗號分割。
- ?用戶授權通過后,應用有權限通過 access_token 調用相應接口。
我這邊是實現的微信小程序綁定抖音,附上微信小程序代碼:
<view class="container"><button class="login-btn" @click="handleDouyinLogin">登錄抖音2</button><view class="web-view-container" v-if="aDouyinLogin.showWebView"><web-view :src="aDouyinLogin.authUrl" bindmessage="handleMessage"></web-view></view><view class="loading" wx:if="{{aDouyinLogin.loading}}">登錄中...</view></view>
const aDouyinLogin = ref({
showWebView: false,
authUrl: 'https://***/api/dy/codeauth',
loading: false,
});// 點擊登錄按鈕,打開抖音授權頁
const handleDouyinLogin = () => {
aDouyinLogin.value.loading =true
aDouyinLogin.value.showWebView =true
};
// 接收 web-view 消息(后端回調后傳遞的信息)
const handleMessage = ((e) => {
const { data } = e.detail;
if (data && data.type === 'douyin_login') {
// 后端返回的登錄結果
handleLoginResult(data);
}
});// 處理登錄結果
const handleLoginResult= ((result) => {
//(result) {
aDouyinLogin.value.loading = false
i