Unity接⼊越南社交软件Zalo登录(Android)之SDK接⼊Zalo登录
注册前的准备⼯作
由于国内⽹络⽆法直接打开Zalo页⾯,因此需要⼀个较稳定的VPN。
创建开发者账号
androidsdk安装步骤登录Zalo
可以在⽹页最底部把⽹页设置为英⽂
创建⾃⼰的应⽤
1.点击右上⾓【创建应⽤】
2.创建好应⽤后记录Application ID和Application secret key 并点击Log in
3.点击Android,填写Package name(unity包名)、Hash key。
如何获取Hashkey,他这⾥是需要SHA1,我们可以通过:
1、win+R 打开cmd命令窗⼝
2、输⼊命令:keytool -list -v -keystore jks路径地址
3、输⼊密钥⼝令
4.得到以下信息
AndroidStudio添加ZaloSDK
1.添加ZaloSDK库以构建gradle
implementation “com.zing.zalo.zalosdk:core:2.6.0329@aar”
implementation “com.zing.zalo.zalosdk:auth:2.6.0329@aar” implementation"com.zing.zalo.zalosdk:openapi:2.6.0329@aar"注:添加@aar是因为AndroidX和Android support有冲突
报错为:
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (:core:1.0.0) and classes.jar (com.android.s upport:support-compat:28.0.0)
Duplicate raphics.drawable.IconCompatParcelizer found in modules classes.jar (:core:1.0.0) and classes.jar (com.andro id.support:support-compat:28.0.0)
Duplicate internal.package-info found in modules classes.jar (:core:1.0.0) and classes.jar (com.android.support:support-c ompat:28.0.0)
Duplicate class androidx.versionedparcelable.CustomVersionedParcelable found in modules classes.jar (androidx.versionedparcelable:versionedparcelabl e:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.NonParcelField found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and c lasses.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelField found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and class es.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelImpl found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and class es.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelImpl$1 found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and cla sses.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.ParcelUtils found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and class es.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel$1 found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) a nd classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcel$ParcelException found in modules classes.jar (androidx.versionedparcelable:versionedparc elable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelParcel found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.
0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelStream found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.
0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelStream$FieldBuffer found in modules classes.jar (androidx.versionedparcelable:versionedpa rcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelStream$InputBuffer found in modules classes.jar (androidx.versionedparcelable:versionedpa rcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelable found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versi
onedparcelable:28.0.0)
Duplicate class androidx.versionedparcelable.VersionedParcelize found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) a nd classes.jar (com.android.support:versionedparcelable:28.0.0)
l中添加appID
⾸先先创建⼀个l
在l⾥⾯添加
<string name="appID"> appID(之前获取的Application ID)</string>
然后在l中添加
<!-- Required zalo app id -->
<meta-data
android:name="com.zing.zalo.zalosdk.appID"
android:value="@string/appID"/>
注:需要根据上述说明添加AppID的l,不能直接在metaData标签中分配appID字符串将导致ZaloSDK⽆法识别appID错误。3.在AndroidManifest⽂件中,添加“应⽤程序名称”属性
<application android:name="com.zing.zalo.zalosdk.oauth.ZaloSDKApplication"/>
如果应⽤程序具有其⾃⼰的Application类,则应⽤程序的onCreate⽅法必须调⽤
public class DemoApplication extends Application {
@Override
public void onCreate(){
ZaloSDKApplication.wrap(this);
}
}
4.在AndroidManifest⽂件中,添加activity
<activity
android:name="com.zing.zalo.zalosdk.oauth.BrowserLoginActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="zalo-appID(之前获取的Application ID)"/>
</intent-filter>
</activity>
5.为zaloSDK添加proguard
-
keep class com.zing.zalo.**{*;}
-keep enum com.zing.zalo.**{*;}
-keep interface com.zing.zalo.**{*;}
注:上述步骤都做完后,可能会有报错,如
Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory)from[com.android.support: support-compat:28.0.0] l:22:18-91
is also present at [:core:1.0.0] l:22:18-86value=(app.CoreComponentFactory).
Suggestion:add ‘tools:replace=“android:appComponentFactory”’ to element l:6:5-26:19 to override.
解决⽅法:
在l⾥添加
tools:replace="android:appComponentFactory"
android:appComponentFactory=""
Zalo登录
1.Zalo授权API
ZaloSDK.Instance.authenticate(Activity, OAuthCompleteListener)//default: LoginVia.APP
ZaloSDK.Instance.authenticate(Activity, LoginVia, OAuthCompleteListener)
LoginVia 有三种登录选项:
LoginVia.APP---------------ZaloApp登录
LoginVia.WEB--------------Zalo⽹页登录
LoginVia.APP_OR_WEB---------------优先App登录,如果设备没安装App则使⽤Web登录
OauthCompleteListener获取登录结果:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论