React-Native集成抖音登录

需要先做好准备工作,依照文档把接入步骤做完,地址:https://open.douyin.com/platform/doc/6850392241442408456
具体代码下载地址
https://github.com/xwh123456/react-native-DouYin
----安卓集成---

image.png

在此处加入这两行
implementation 'com.bytedance.ies.ugc.aweme:opensdk-china-external:0.1.3.0'
implementation 'com.bytedance.ies.ugc.aweme:opensdk-common:0.1.3.0'

image.png

在git上下载放在该目录下分别加入这几处


image.png

import com.bytedance.sdk.open.douyin.DouYinOpenApiFactory;
import com.bytedance.sdk.open.douyin.DouYinOpenConfig;


image.png

packages.add(new Douyin());
image.png

DouYinOpenApiFactory.init(new DouYinOpenConfig(clientkey));

在JS代码中加入
const { DouYin } = NativeModules;
DouYin.sendAuthRequest('user_info', '', (res: any) => {
console.log(res);
})
该处是发送请求然后监听返回值,componentDidMount中
DeviceEventEmitter.addListener('DouYin_Resp', resp => {
// emitter.emit('DouYin_Resp', resp);
console.log(resp);
Toast.info(JSON.stringify(resp));
if (resp.authCode) {
this.handleDyOauth(resp.authCode);
}
});

---ios集成---
ios的集成步骤请看官方文档 https://open.douyin.com/platform/doc集成工作完成后把两个文件拖到ios的根目录

image.png

需要主动注册
在JS代码中就可以调用
const { dyModule } = NativeModules;
dyModule.sendDyRequest('','',(res)=>{
console.log(res);
if(res){
this.handleDyOauth(res);
}
})

如果有疑问可以留言,最好点一个star,谢谢

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。