
抖音sdk 回调packagecom.包名.douyinapi;importcom.bytedance.sdk.open.douyin.DouYinOpenConfig;importcom.bytedance.sdk.open.douyin.DouYinOpenApiFactory;importcom.bytedance.sdk.open.douyin.api.DouYinOpenApi;importcom.bytedance.sdk.open.aweme.CommonConstants;importcom.bytedance.sdk.open.aweme.authorize.model.Authorization;importcom.bytedance.sdk.open.aweme.common.handler.IApiEventHandler;importcom.bytedance.sdk.open.aweme.common.model.BaseReq;importcom.bytedance.sdk.open.aweme.common.model.BaseResp;importcom.bytedance.sdk.open.aweme.share.Share;importandroid.content.Context;importandroid.os.Bundle;importandroid.app.Activity;importandroid.content.Intent;importandroid.util.Log;importandroid.text.TextUtils;importandroid.provider.Settings;importandroidx.annotation.NonNull;importandroid.util.SparseArray;importorg.json.JSONObject;publicclassDouYinEventActivityextendsActivityimplementsIApiEventHandler{DouYinOpenApidouYinOpenApi;privatestaticfinalStringGameManagerGameManagerOverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);douYinOpenApiDouYinOpenApiFactory.create(this);douYinOpenApi.handleIntent(getIntent(),this);}OverridepublicvoidonReq(BaseReqreq){}OverridepublicvoidonResp(BaseRespresp){sendMessageToUnity(OnLoginSuccess, 返回成功);Log.d(unity, 授权返回);// 授权成功可以获得authCodeif(resp.getType()CommonConstants.ModeType.SEND_AUTH_RESPONSE){Authorization.Responseresponse(Authorization.Response)resp;if(resp.isSuccess()){Log.d(unity,授权成功code ${response.authCode});}else{Log.d(unity,授权失败 ${resp.errorCode} ${resp.errorMsg});}}}OverridepublicvoidonErrorIntent(Intentintent){// 错误数据// Toast.makeText(this, intent出错啦, Toast.LENGTH_LONG).show();Log.d(unity,Intent出错 );}privatevoidsendMessageToUnity(Stringmothod,Stringmessage){Log.d(unity,mothod: mothod message:message);if(TextUtils.isEmpty(GameManager)){Log.e(unity,gameObject is null, please set gameObject first);return;}UnityPlayer.UnitySendMessage(GameManager,mothod,message);}}接SDK时出现的问题以及解决方案1、报错内容Exception: Field currentActivity or type signature not found解决方案以下方法获取需要再unity启动完成后调用不能在Awake调用androidJavaClass new AndroidJavaClass(“com.unity3d.player.UnityPlayer”);androidJavaObject androidJavaClass.GetStatic(“currentActivity”);2、获取不到DouYinOpenSDKConfig 类处理方法检查一确认依赖包是否有配置 按照官网配置即可检查二引入路径不对正确的路径是 :import com.bytedance.sdk.open.aweme.init.DouYinOpenSDKConfig;其它宿主注入 路径import com.bytedance.sdk.open.aweme.core.OpenLogService;import com.bytedance.sdk.open.aweme.core.OpenNetworkService;import com.bytedance.sdk.open.aweme.core.OpenHostInfoService;import com.bytedance.sdk.open.aweme.core.OpenHostTicketService;import com.bytedance.sdk.open.aweme.core.OpenCallback;3、DouYinOpenSDKConfig.Builder() ,找不到 Builder() 符号处理方法检查语法格式抖音文档是kotlin编程语言需要换成java例如 DouYinOpenSDKConfig config new DouYinOpenSDKConfig.Builder()4、控制台白名单授权状态一直显示待授权配置已添加request.scope “trial.whitelist,user_info”;处理方法获取到code需要服务器获取 access_token才算真正的获取权限成功