为啥我无法登录 Agora RTM?

Posted

技术标签:

【中文标题】为啥我无法登录 Agora RTM?【英文标题】:Why can't I login to the Agora RTM?为什么我无法登录 Agora RTM? 【发布时间】:2021-09-02 14:44:32 【问题描述】:

我正在尝试在我的应用程序中实现 RTM,我一步一步按照官方文档进行操作,但是当我尝试登录 RTM 服务器(使用 App ID only 方法)时,什么也没有发生,我实现的代码基于登录从未实现,我查看了 agorartm.log 文件,发现 rtmClient 的初始化是成功的,但是我没有看到有关登录 rtmClient 的任何信息,当我查看项目的使用页面时,我看到了RTM 的每日活跃用户中有一个用户,但这只是在第二天我登录而不是在同一天出现,这很奇怪。

-这是我用来初始化 rtmClient 并登录它的方法:

private void loginToRtm(String uid,RtmLoginCallback rtmLoginCallback)
    
    String appId = getString(R.string.AGORA_APP_ID);
    try
    
     /*Initializing RtmClient*/
     rtmClient = RtmClient.createInstance(this, appId, new RtmClientListener() 
        @Override
        public void onConnectionStateChanged(int i, int i1) 

        

      @Override
      public void onMessageReceived(RtmMessage rtmMessage, String s) 

        
    @Override
    public void onImageMessageReceivedFromPeer(RtmImageMessage rtmImageMessage, String s) 

    

    @Override
    public void onFileMessageReceivedFromPeer(RtmFileMessage rtmFileMessage, String s) 

    

    @Override
    public void onMediaUploadingProgress(RtmMediaOperationProgress rtmMediaOperationProgress, long l) 

    

    @Override
    public void onMediaDownloadingProgress(RtmMediaOperationProgress rtmMediaOperationProgress, long l) 

    

    @Override
    public void onTokenExpired() 

    

    @Override
    public void onPeersOnlineStatusChanged(Map<String, Integer> map) 

    
);



catch (Exception e)

    throw new RuntimeException("RTM initialization failed!");


//Login to rtmClient
rtmClient.login(null, uid, new ResultCallback<Void>() 
    @Override
    public void onSuccess(Void aVoid) 

        rtmLoginCallback.rtmLoginOnCallback();

        Toast.makeText(context, uid + "Successful login to RTM", Toast.LENGTH_SHORT).show();
    

    @Override
    public void onFailure(ErrorInfo errorInfo) 

        rtmLoginCallback.rtmLoginOnCallback();

        Toast.makeText(context, uid + "failed to login to RTM"+errorInfo.toString(), Toast.LENGTH_SHORT).show();

        Log.d("RTM_LOGIN : ","Failed");
    
);

-这是我在清单文件中使用的权限:

<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

-这是我的 agorartm.log 文件:

     INFO    2021-09-02T10:45:48:860   4775; Agora Logger Started
        INFO    2021-09-02T10:45:48:860   4775; Agora SDK ver 1.4.7 build 538, built on Jul 15 2021 20:46:30
        INFO    2021-09-02T10:45:

48:860   4775; Agora SDK git ver:480914647 and branch:HEAD
    INFO    2021-09-02T10:45:48:860   4845; set_thread_priority returns 1
    INFO    2021-09-02T10:45:48:861   4775; initialize plugin manager
    INFO    2021-09-02T10:45:48:861   4775; built-in encryption is enabled
    INFO    2021-09-02T10:45:48:862   4775; built-in ssl is enabled
    INFO    2021-09-02T10:45:48:862   4775; use event engine
    INFO    2021-09-02T10:45:48:864   4775; CacheManager: save cache to storage elapsed 2
    INFO    2021-09-02T10:45:48:864   4775; create agora service
    INFO    2021-09-02T10:45:48:864   4775; platform is LINUX
    INFO    2021-09-02T10:45:48:865   4775; platform is ANDROID
    INFO    2021-09-02T10:45:48:865   4775; [xdump] init enable:1, dumpfile:1
    INFO    2021-09-02T10:45:48:873   4775; create rtm service, count:1
    INFO    2021-09-02T10:45:48:874   4775; [rtm-API] rtm service initialize
    INFO    2021-09-02T10:45:48:874   4775; [rtm-API] rtm start service
    INFO    2021-09-02T10:45:48:875   4846; AgoraServiceThread Thread started: 0x78a9bc92a0
    INFO    2021-09-02T10:45:48:921   4846; The selected AP IPs are 101.132.108.165,123.56.235.221,.
    INFO    2021-09-02T10:45:48:921   4846; The selected AP IPs are 2406:da14:97f:4701:52:194:158:59,112.126.96.46,2600:1f18:64ea:9401:50:17:126:121,106.14.12.130,118.190.148.38,47.107.39.93,.
    INFO    2021-09-02T10:45:48:921   4846; [ap] queryDns normal domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:921   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:921   4846; [cm] queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:921   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:923   4846; [ap] queryDns TLS domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:923   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:923   4846; [cm] queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:923   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:924   4854; AgoraRtmThread Thread started: 0x7889ce60e0
    INFO    2021-09-02T10:45:48:925   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:925   4846; The selected AP IPs are 123.56.235.221,101.132.108.165,.
    INFO    2021-09-02T10:45:48:925   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,47.107.39.93,2406:da14:97f:4701:52:194:158:59,112.126.96.46,118.190.148.38,106.14.12.130,.
    INFO    2021-09-02T10:45:48:925   4846; [ap] queryDns normal domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [base_context]queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [cm] queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [base_context]queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [ap] queryDns TLS domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [base_context]queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [cm] queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [base_context]queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:926   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:926   4846; The selected AP IPs are 101.132.108.165,123.56.235.221,.
    INFO    2021-09-02T10:45:48:926   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,47.107.39.93,2406:da14:97f:4701:52:194:158:59,112.126.96.46,106.14.12.130,118.190.148.38,.
    INFO    2021-09-02T10:45:48:926   4846; [ap] queryDns normal domain is ap1.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [base_context]queryDns domain is ap1.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [cm] queryDns domain is ap1.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [base_context]queryDns domain is ap1.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [ap] queryDns TLS domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [cm] queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:926   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:926   4846; The selected AP IPs are 123.56.235.221,101.132.108.165,.
    INFO    2021-09-02T10:45:48:926   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,118.190.148.38,2406:da14:97f:4701:52:194:158:59,47.107.39.93,106.14.12.130,112.126.96.46,.
    INFO    2021-09-02T10:45:48:926   4846; [ap] queryDns normal domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [cm] queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [ap] queryDns TLS domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [cm] queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:927   4846; The selected AP IPs are 101.132.108.165,123.56.235.221,.
    INFO    2021-09-02T10:45:48:927   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,106.14.12.130,2406:da14:97f:4701:52:194:158:59,118.190.148.38,112.126.96.46,47.107.39.93,.
    INFO    2021-09-02T10:45:48:927   4846; [ap] queryDns normal domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [cm] queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [ap] queryDns TLS domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [cm] queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 123.56.235.221,101.132.108.165,.
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,106.14.12.130,2406:da14:97f:4701:52:194:158:59,47.107.39.93,118.190.148.38,112.126.96.46,.
    INFO    2021-09-02T10:45:48:928   4846; [ap] queryDns normal domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [cm] queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [ap] queryDns TLS domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [cm] queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 123.56.235.221,101.132.108.165,.
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,106.14.12.130,2406:da14:97f:4701:52:194:158:59,118.190.148.38,112.126.96.46,47.107.39.93,.
    INFO    2021-09-02T10:45:48:928   4846; [ap] queryDns normal domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [cm] queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [ap] queryDns TLS domain is ap2-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap2-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [cm] queryDns domain is ap2-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap2-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 101.132.108.165,123.56.235.221,.
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 2406:da14:97f:4701:52:194:158:59,112.126.96.46,2600:1f18:64ea:9401:50:17:126:121,106.14.12.130,47.107.39.93,118.190.148.38,.
    INFO    2021-09-02T10:45:48:929   4846; [ap] queryDns normal domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [cm] queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [ap] queryDns TLS domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [cm] queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:929   4846; The selected AP IPs are 101.132.108.165,123.56.235.221,.
    INFO    2021-09-02T10:45:48:929   4846; The selected AP IPs are 2406:da14:97f:4701:52:194:158:59,118.190.148.38,2600:1f18:64ea:9401:50:17:126:121,47.107.39.93,112.126.96.46,106.14.12.130,.
    INFO    2021-09-02T10:45:48:929   4846; [ap] queryDns normal domain is ap2.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap2.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [cm] queryDns domain is ap2.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap2.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [ap] queryDns TLS domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [cm] queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:929   4846; The selected AP IPs are 123.56.235.221,101.132.108.165,.
    INFO    2021-09-02T10:45:48:929   4846; The selected AP IPs are 2406:da14:97f:4701:52:194:158:59,112.126.96.46,2600:1f18:64ea:9401:50:17:126:121,118.190.148.38,106.14.12.130,47.107.39.93,.
    INFO    2021-09-02T10:45:48:929   4846; [ap] queryDns normal domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [cm] queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:930   4846; [ap] queryDns TLS domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:930   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:930   4846; [cm] queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:930   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.message.enable_advanced_e2e_scale from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.media.chunk_timeout from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_indian_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_south_america_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.encryption_level from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_na_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_africa_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_oceania_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_jp_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.message.enable_p0_scale from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_as_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_as_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_south_america_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_eur_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_cn_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_africa_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_oceania_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_cn_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_indian_area from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [CS]: found no value for key rtm.ip_jp_area from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [CS]: found no value for key rtm.ip_eur_area from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [CS]: found no value for key rtm.link_port from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [CS]: found no value for key rtm.peer.end_call_enabled from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [CS]: found no value for key rtm.ip_tls_na_area from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [rtm-context] initialization started.
    INFO    2021-09-02T10:45:48:931   4846; [rtm-context] TLS-configuration started.
    INFO    2021-09-02T10:45:48:931   4846; [rtm-context] TLS-configuration succeed.
    INFO    2021-09-02T10:45:48:931   4846; [rtm-context] initialization succeed.

here is a link to a screenshot of my project usage page on the Agora Console showing that there is a user logged in

【问题讨论】:

【参考方案1】:

以防万一其他人遇到这个问题,我就是这样解决的:

我实现了 Agora RTM 1.4.1 版:

'com.github.agorabuilder:rtm-sdk:1.4.1'

而不是版本 1.4.7 然后在我的设备上运行我的应用程序,发现问题的原因是 Agora 在另一个线程(在主线程之外)实现了 RTM 的 Login 方法,所以我得到了这个异常:

java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

我搜索此错误并找到有关此问题的解决方案: Can't toast on a thread that has not called Looper.prepare()

我使用了@nhoxbypass 回答提供的代码:

runOnUiThread(new Runnable() 
  public void run() 
     final Toast toast = Toast.makeText(context, "GAME OVER!\nScore: " + score, duration);
     toast.show();
  
  );

这个错误的原因是我在主 UI 线程之外进行了祝酒。 所以基本上 Agora 在他们的 SDK 的较新版本中处理了这个异常,所以我无法看到这个错误并解决问题,他们也没有提到他们的方法在主线程之外运行,并且在他们的文档中: https://docs.agora.io/en/Real-time-Messaging/messaging_android?platform=Android#2-implement-the-logic-of-sending-and-receiving-messages 他们在主线程内祝酒,这是完全错误的。 后来我回到 Agora RTM 1.4.7 版本并运行我的应用程序,我能够成功登录。

【讨论】:

【参考方案2】:

看起来文档已经更新并添加了uithread:

https://docs.agora.io/en/Real-time-Messaging/messaging_android?platform=Android#2-implement-the-logic-of-sending-and-receiving-messages

            @Override
            public void onFailure(ErrorInfo errorInfo) 
                CharSequence text = "User: " + uid + " failed to log in to the RTM system!" + errorInfo.toString();
                int duration = Toast.LENGTH_SHORT;
                runOnUiThread(new Runnable() 
                    public void run() 
                        Toast toast = Toast.makeText(getApplicationContext(), text, duration);
                        toast.show();
                    
                );

            

【讨论】:

以上是关于为啥我无法登录 Agora RTM?的主要内容,如果未能解决你的问题,请参考以下文章

Agora Cloud 教室登录失败

错误:包 io.agora.rtm 不存在

为啥无法登录 Google Play 服务?

为啥我的 iOS 应用无法使用 Node.js Agora Token Server 创建的令牌通过 AgoraRtcEngineKit 进行身份验证?

为啥无法使用苹果按钮登录?

为啥我的 Spring 应用程序无法识别有人已经登录?