android - Azure 移动服务 native Android 登录

标签 android azure azure-mobile-services

我有一个 Easy API 和一个 Easy Table 在 Azure 移动服务上运行。这两个都需要身份验证才能访问。我还设置了 Google 身份验证。现在,当我尝试使用 android 应用程序连接到移动服务时,我会得到 Google 登录页面的 WebView,而应用程序启动时我已经对用户进行了身份验证。我按照以下指南在 Android 上设置身份验证并测试将单个对象发布到表中。

https://azure.microsoft.com/en-in/documentation/articles/mobile-services-android-how-to-use-client-library/#authentication

这是我用于身份验证和添加到表中的代码。使用此 WebView 登录后,数据也不会插入到表中。它会默默地失败,没有任何错误或警告。

创建客户端。 Azure 门户上没有提供 API key ,我读到 here现在不需要那个了。但 SDK 没有更新,所以我传递了一个空字符串。

try {
    mClient = new MobileServiceClient(
            "https://memoriesapp.azurewebsites.net",
            "",  
            this
    );
} catch (MalformedURLException e) {
    e.printStackTrace();
}


final MobileServiceTable<Trip> mTripTable = mClient.getTable(Trip.class);
// Login using the Google provider.

ListenableFuture<MobileServiceUser> mLogin = mClient.login(MobileServiceAuthenticationProvider.Google);

Futures.addCallback(mLogin, new FutureCallback<MobileServiceUser>() {
    @Override
    public void onFailure(Throwable exc) {

    }

    @Override
    public void onSuccess(MobileServiceUser user) {
        Snackbar.make(findViewById(R.id.new_trip_layout),String.format(
                "You are now logged in - %1$2s",
                user.getUserId()), Snackbar.LENGTH_LONG);
    }
});

new AsyncTask<Void, Void, Void>() {

    @Override
    protected Void doInBackground(Void... params) {
        try {
            mTripTable.insert(trip1).get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return null;
    }
}.execute();

这是我参加该 Activity 时得到的结果:

Imgur

最佳答案

听起来您正在将 Azure 应用服务与 Azure 移动服务混合和匹配。

移动服务确实需要 API key 。 应用服务没有。

您正在指向移动服务的文档 - 如果您正在遵循该教程,则需要添加 API key 。如果您不这样做,后端将返回 401 Unauthorized,并且您可能会被重定向到登录页面。

关于android - Azure 移动服务 native Android 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35576421/

相关文章:

azure - 在 Microsoft Azure 门户中创建 SQL 数据库时,如果我的 "Region"不在列表中,该怎么办?

c# - 由于文件锁定 (msvcr100.dll),TFS CI 构建 Azure Web App(应用服务)失败

asp.net - 如何在 Azure 移动应用中的 SignalR.Hub 中获取 MobileAppSettingsDictionary

android - 如何在android中剪切音频文件并与视频文件合并?

java - 应用程序停止工作

Azure Cosmos DB - 是否可以使用并非所有文档都存在的 JSON 字段作为分区键?

push-notification - 用于聊天等实时应用程序的 Signal R 与推送通知

entity-framework - 如何从一个 Azure 移动服务 TableController 包装的表从另一个 TableController 访问?

android - TextView的onDraw支持图形绘制吗?

java - LIBGDX "parsing error emitter"具有 2 个或更多发射器