我有一个 Easy API 和一个 Easy Table 在 Azure 移动服务上运行。这两个都需要身份验证才能访问。我还设置了 Google 身份验证。现在,当我尝试使用 android 应用程序连接到移动服务时,我会得到 Google 登录页面的 WebView,而应用程序启动时我已经对用户进行了身份验证。我按照以下指南在 Android 上设置身份验证并测试将单个对象发布到表中。
这是我用于身份验证和添加到表中的代码。使用此 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 时得到的结果:
最佳答案
听起来您正在将 Azure 应用服务与 Azure 移动服务混合和匹配。
移动服务确实需要 API key 。 应用服务没有。
您正在指向移动服务的文档 - 如果您正在遵循该教程,则需要添加 API key 。如果您不这样做,后端将返回 401 Unauthorized,并且您可能会被重定向到登录页面。
关于android - Azure 移动服务 native Android 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35576421/