我一直在使用谷歌應用程序引擎的樣品(移動購物助理)https://github.com/GoogleCloudPlatform/MobileShoppingAssistant-sample/tree/master/MobileAssistantAndroidAppEngine。我花了大約一週的時間來設置項目並修復問題(主要與依賴和配置有關)。現在後端部署了,我可以通過api explorer訪問api。我可以執行非受限方法並從服務器獲取響應,但是當我執行管理方法時,即使在打開OAuth時也會收到錯誤。註冊與後端應用程序失敗發動機的示例代碼
OK 401
message: Only authenticated users may invoke this operation
,所以我認爲這個問題是由於不良的配置
這裏是我做了什麼:
應用gradle.build
apply from: 'config.gradle'
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.google.sample.mobileassistant"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile project(path: ':backend', configuration: 'android-endpoints')
}
應用構建配置
buildConfigField "String", "ROOT_URL",
"\"https://MY_PROJECT_ID.appspot.com/_ah/api/\""
buildConfigField "boolean", "SIGN_IN_REQUIRED", "true"
buildConfigField "String", "SENDER_ID", "\"MY_SENDER_ID\""
buildConfigField "String", "WEB_CLIENT_ID", "\"MY_WEB_CLIENT_ID\""
而且build.gradel的後端中,我已經改變了應用程序引擎的SDK版本,從18至30
>>注:機器人工作室的檢查報告,下,appcfg和端點符號無法解析!
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.30'
}
}
repositories {
mavenCentral();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.30'
compile 'com.google.appengine:appengine-endpoints:1.9.30'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.30'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.30'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.googlecode.objectify:objectify:5.1.5'
compile 'com.ganyo:gcm-server:1.0.2'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
}
}
項目ID在appengine_web.xml以及API密鑰設置。當我運行的客戶端應用程序獲得REG_ID但註冊失敗由於GoogleAuthIOException:
E/MainActivity: Exception=com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
其從sendRegistrationIdToBackend()方法拋出:
/**
* Sends the registration ID to your server over HTTP, so it can use
* GCM/HTTP or CCS to send messages to your app. Not needed for this
* demo since the device sends upstream messages to a server that echoes
* back the message using the 'from' address in the message.
*/
private void sendRegistrationIdToBackend() {
try {
shoppingAssistantAPI.registrations()
.registerDevice(regId).execute();
// Persist the registration ID - no need to register again.
storeRegistrationId(context, regId);
} catch (IOException e) {
LOG.warning("Exception when sending registration ID to the "
+ "backend = "+ e.getMessage());
// If there is an error, we will try again to register the
// device with GCM the next time the MainActivity starts.
}
}
現在這個方法調用
shoppingAssistantAPI.registrations()
.registerDevice(regId).execute();
但是在後端的源代碼有不同的類名和方法簽名...類Registration.class與getter和setter方法& RegistrationEndpoint枝條registerDevice(字符串的RegID,UserAccount用戶)
而這正是我感到困惑? 有人可以向我解釋這個代碼有什麼問題,以及我如何讓客戶端應用程序正確地與後端通信。
--- UPDATE ---
客戶端應用程序請求的方法(chickIn法),這需要一個說法,尚不可用(REGID)這種奇怪的!
03-01 20:07:48.898 25083-25359/com.google.sample.mobileassistant W/MainActivity: Exception when checking in =com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
03-01 20:07:51.581 25083-25359/com.google.sample.mobileassistant W/MainActivity: Exception when sending registration ID to the backend = null
03-01 20:07:51.601 25083-25083/com.google.sample.mobileassistant I/MainActivity: Device registered, registration ID= APA91bF2eC6o9_KBI2coPMqqXE94lECzeYLnrD30nmK2PvmoHg3pFfVuxYkLir3HPV07gq-n-UZZOsM1EUSQOfR8WnWYaG1iDFbx0IuIOLNKIMdeDimPAH5H7DURDqZZ8hWdrsStnS4sEHHTB155bx91L7FpV0txHA
03-01 20:07:52.292 25083-25359/com.google.sample.mobileassistant E/MainActivity: Exception=com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
我記得你必須在開發者控制檯中設置你正在使用的用戶登錄管理區域的所有者。 – dmaij
hi @dmaij ...我應該在哪裏添加用戶?...在配置文件中?可以解釋更多 – msdev16
不,在Google開發者控制檯中,應該有一個項目所有者應該用於登錄到管理員部分。您應該無法使用設備實際登錄到管理員部分。 – dmaij