" getAccountInfo()。userName"的等价物是什么?在Dropbox API v2中?

时间:2018-03-13 18:04:15

标签: android api dropbox boxapiv2

在Dropbox API v1中,我使用了:

String userName = dropboxAccount.getAccountInfo().userName;

获取用户名并在屏幕上显示。

现在我使用API​​ v2,所以我尝试了以下代码:

public String getLoggedAccount()
{
    String userAccountStr;

    if (sDbxClient == null)
        return "N/A";

    try
    {
        userAccountStr  = sDbxClient.users().getCurrentAccount().getAccountId();
        userAccountStr += ", ";

        userAccountStr += sDbxClient.users().getCurrentAccount().getEmail();
        userAccountStr += ", ";
        return userAccountStr;
    }

    catch(IllegalArgumentException e)
    {
        mException = e;
    }

    catch(NullPointerException e)
    {
        mException = e;
    }

    catch (com.dropbox.core.DbxException e)
    {
        mException = e;
    }

    return "N/A";
}

但它在" getAccountId()"上崩溃了线上,永远不要去任何关于' catch'线。

可能是什么问题?

========== ========= ========= ========== ========= =

以下是一些更多信息:

我参加了新的Dropbox API v2附带的Anroid示例项目,紧接着该行:

sDbxClient = new DbxClientV2(requestConfig, accessToken);

我添加了对以下功能的调用:

private static String getLoggedAccount()
{
    if (sDbxClient == null)
        return "N/A";

    FullAccount dbxAccountInfo;

    try
    {
        dbxAccountInfo = sDbxClient.users().getCurrentAccount();
    }

    catch (DbxException ex)
    {
        System.err.println("Error making API call: " + ex.getMessage());
        System.exit(1);
        return "N/A";
    }

    System.out.print(dbxAccountInfo.toStringMultiline());
}

它在getCurrentAccount()行崩溃,永远不会到达catch。在Logcat窗口中,我看到 FATAL EXCEPTION

03-14 14:11:52.400 7870-7870 / com.dropbox.core.examples.android I / System.out:调试器已解决(1465) 03-14 14:11:52.468 7870-7870 / com.dropbox.core.examples.android W / System:ClassLoader引用了未知路径:/data/app/com.dropbox.core.examples.android-2/lib/arm

03-14 14:12:11.779 7870-7870 / com.dropbox.core.examples.android E / AndroidRuntime: FATAL EXCEPTION :main                                                                                  过程:com.dropbox.core.examples.android,PID:7870                                                                                  java.lang.RuntimeException:无法恢复活动{com.dropbox.core.examples.android/com.dropbox.core.examples.android.UserActivity}:android.os.NetworkOnMainThreadException                                                                                      在android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)                                                                                      在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)                                                                                      在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)                                                                                      在android.app.ActivityThread.-wrap11(ActivityThread.java)                                                                                      在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)                                                                                      在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                      在android.os.Looper.loop(Looper.java:148)                                                                                      在android.app.ActivityThread.main(ActivityThread.java:5417)                                                                                      at java.lang.reflect.Method.invoke(Native Method)                                                                                      在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                                      在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)                                                                                   引起:android.os.NetworkOnMainThreadException                                                                                      在android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)                                                                                      at java.net.InetAddress.lookupHostByName(InetAddress.java:431)                                                                                      at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)                                                                                      在java.net.InetAddress.getAllByName(InetAddress.java:215)                                                                                      在com.android.okhttp.internal.Network $ 1.resolveInetAddresses(Network.java:29)                                                                                      在com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:188)                                                                                      在com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:157)                                                                                      在com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:100)                                                                                      在com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:357)                                                                                      在com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:340)                                                                                      在com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)                                                                                      在com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)                                                                                      在com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:437)                                                                                      在com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:114)                                                                                      在com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:245)                                                                                      在com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)                                                                                      在com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)                                                                                      在com.dropbox.core.http.StandardHttpRequestor.getOutputStream(StandardHttpRequestor.java:123)                                                                                      在com.dropbox.core.http.StandardHttpRequestor.access $ 000(StandardHttpRequestor.java:28)                                                                                      在com.dropbox.core.http.StandardHttpRequestor $ Uploader。(StandardHttpRequestor.java:133)                                                                                      在com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:72)                                                                                      在com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:28)                                                                                      在com.dropbox.core.DbxRequestUtil.startPostRaw(DbxRequestUtil.java:237)                                                                                      在com.dropbox.core.v2.DbxRawClientV2 $ 1.execute(DbxRawClientV2.java:107)                                                                                      在com.dropbox.core.v2.DbxRawClientV2.executeRetriable(DbxRawClientV2.java:284)                                                                                      在com.dropbox.core.v2.DbxRawClientV2.rpcStyle(DbxRawClientV2.java:102)                                                                                      at com.dropbox.core.v2.users.DbxUserUsersRequests.getCurrentAccount(DbxUserUsersRequests.java:120)                                                                                      在com.dropbox.core.examples.android.DropboxClientFactory.getLoggedAccount(DropboxClientFactory.java:31)                                                                                      在com.dropbox.core.examples.android.DropboxClientFactory.init(DropboxClientFactory.java:91)                                                                                      在com.dropbox.core.examples.android.DropboxActivity.initAndLoadData(DropboxActivity.java:43)                                                                                      在com.dropbox.core.examples.android.DropboxActivity.onResume(DropboxActivity.java:32)                                                                                      在com.dropbox.core.examples.android.UserActivity.onResume(UserActivity.java:63)                                                                                      在android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1258)                                                                                      在android.app.Activity.performResume(Activity.java:6327)                                                                                      在android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092)                                                                                     .. 03-14 14:16:13.708 7870-7870 /? I /处理:发送信号。 PID:7870 SIG:9

有帮助吗?

0 个答案:

没有答案