抖音开发者平台授权白名单步骤。(获取授权码(code) ,调用接口,提示重定向地址非法)

1.用这个url去换取code

https://open.douyin.com/platform/oauth/connect?client_key=【你的client_key】&response_type=code&scope=trial.whitelist&redirect_uri=https%3A%2F%2Fwww.douyin.com

https://open.douyin.com/platform/oauth/connect?client_key=awq7clitdigv2b8c&response_type=code&scope=trial.whitelist&redirect_uri=https://www.douyin.com

2.上面会跳转到这个url

https://www.douyin.com/?code=【是你的code,会根据你的请求改变】&scopes=trial.whitelist&state=&recommend=1

3.把code调用授权接口即可绑定白名单

    
import com.aliyun.tea.TeaException;
import com.douyin.openapi.client.Client;
import com.douyin.openapi.client.models.OauthAccessTokenRequest;
import com.douyin.openapi.client.models.OauthAccessTokenResponse;
import com.douyin.openapi.credential.models.Config;
import com.istudy.meizhen.api.matrix.config.DouYinConfig;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * @author 落尘
 * @since 2024-11-02 14:03:06
 */
@SpringBootTest
@Slf4j
class DouYinServiceTest {

    @Autowired
    private DouYinService douYinService;

    @Autowired
    DouYinConfig douYinCode;

    @Test
    void getCode() {
        try {
            Config config = new Config().setClientKey(douYinCode.getClientKey()).setClientSecret(douYinCode.getClientSecret()); // 改成自己的app_id跟secret
            Client client = new Client(config);
            /* 构建请求参数,该代码示例中只给出部分参数,请用户根据需要自行构建参数值
                token:
                   1.若用户自行维护token,将用户维护的token赋值给该参数即可
                   2.SDK包中有获取token的函数,请根据接口path在《OpenAPI SDK 总览》文档中查找获取token函数的名字
                     在使用过程中,请注意token互刷问题
                header:
                   sdk中默认填充content-type请求头,若不需要填充除content-type之外的请求头,删除该参数即可
            */
            OauthAccessTokenRequest sdkRequest = new OauthAccessTokenRequest();
            sdkRequest.setClientKey(douYinCode.getClientKey());
            sdkRequest.setClientSecret(douYinCode.getClientSecret());
            sdkRequest.setCode("da35fc4e6106813er3r8k6MKkA8sLwJgwnrS_lq");
            sdkRequest.setGrantType("authorization_code");
            OauthAccessTokenResponse sdkResponse = client.OauthAccessToken(sdkRequest);
            log.info("sdkResponse={}", sdkResponse.getData());
        } catch (Exception e) {
            log.error("error={}", e.getMessage());
        }
    }

    /**
     * 转码
     */
    public static void main(String[] args) throws UnsupportedEncodingException {
        System.out.println(URLEncoder.encode("https://www.douyin.com/user/self", "UTF-8"));
    }
}

4.常见问题
1)redirect_uri没有转码或者有特殊字符导致页面提示重定向地址非法
2)有可能没配置回调地址(最容易忽略)
抖音回调地址

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值