0
請幫幫我吧!我在應用程序中有一個列表文件,這些文件可以標記爲已讀和未讀。執行此操作時,會向服務器發出請求以存儲此狀態。但是,我遇到了一個錯誤:Android Retrofit2 RxJava,Google身份驗證令牌如何解決錯誤?
04-06 06:30:00.384 22760-1489/me.android.app D/OkHttp: <-- 400 BAD REQUEST https://api.me/api/v1/2/setDocumentAttribute?token=q4B97JQBCKcZYCjVVw6v-cFMC4I2JoMd-MmCir7VvuLZl15J_Ztqm2JpbKwraRDmqWEyZOxJWzoy_eOKv0U2XX2a-9GL_7cXkOMyT20BLaqHb3nJSGoJnPU2cCFigEtC4TLhSIh_brpF_KNNeZ8_MqzEaomiTSYVtkx6RnL7ohPLPh8ZjMK2ow%3D%3D&documentID=33fe7dcb697f613c56f449754e923c53&path=Personal&attrName=isNew (99ms)
04-06 06:30:00.384 22760-1489/me.android.app D/OkHttp: Access-Control-Allow-Origin: *
04-06 06:30:00.384 22760-1489/me.android.app D/OkHttp: Content-Type: application/json
04-06 06:30:00.384 22760-1489/me.android.app D/OkHttp: Date: Thu, 06 Apr 2017 03:30:00 GMT
04-06 06:30:00.384 22760-1489/me.android.app D/OkHttp: Server: Apache/2.4.23 (Amazon) mod_wsgi/3.5 Python/2.7.12
04-06 06:30:00.384 22760-1489/me.android.app D/OkHttp: Content-Length: 97
04-06 06:30:00.384 22760-1489/me.android.app D/OkHttp: Connection: keep-alive
04-06 06:30:00.384 22760-1489/me.android.app D/OkHttp: {"message": "Input payload validation failed", "errors": {"token": "Security token"}}
API服務器有這樣的參數:
"parameters": [
{
"in": "query",
"type": "string",
"description": "Pagination token",
"name": "pageToken"
},
{
"in": "query",
"type": "string",
"description": "(True, False) Returns hierachy only, including empty folders",
"name": "hierarchyOnly"
},
{
"in": "query",
"type": "string",
"description": "Parent folder ID",
"name": "parent"
},
{
"in": "query",
"type": "string",
"description": "Valid security token",
"name": "token"
},
{
"description": "An optional fields mask",
"format": "mask",
"type": "string",
"name": "X-Fields",
"in": "header"
}
]
在Android中我有其他方法ApiServiceInterface:
@POST("setDocumentAttribute")
Observable<String> setDocumentAttribute(
@Query(TOKEN) String token,
@Query(DOCUMENT_ID) String documentId,
@Query("path") String path,
@Query("attrName") String attrName);
在這裏,我寫下了一致方法調用鏈,當我做調試時。我真的希望它會很清楚。
DocCompanyPresenter
public void onClickThumbnailToggle(DocItem docItem) {
Log.d(TAG, "***onClickThumbnailToggle");
if (getView() != null) {
String docId = docItem.getDocLink();
if (!TextUtils.isEmpty(docId)) {
boolean toggle = docItem.getNewDocs()>0;
if (toggle) {
docItem.setNewDocs(0); // make star (read)
Log.d(TAG, "***done read");
} else {
docItem.setNewDocs(1); // make isNew (unread)
Log.d(TAG, "***done unread");
}
getView().updateListDocs(getDocPos(docItem.getDocLink()));
getView().toggleDocument(leftPanelDocIdMark,!toggle); ->
docId = docId.substring(0,docId.indexOf("."));
toggleDocument.toggleDocument(docId,docItem.getPath(),!toggle)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
}
}
}
FolderCompanyFragment
@Override
public void toggleDocument(String folderId, boolean toggle) {
toggleDocument.actionToggleDocument(folderId,toggle); ->
}
->
MainActivity
@Override
public void actionToggleDocument(String folderId, boolean toggle) {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FolderListFragment.TAG);
if (fragment instanceof ActionToggleDocument) {
((ActionToggleDocument) fragment).actionToggleDocument(folderId,toggle); ->
}
}
->
FolderListFragment
@Override
public void actionToggleDocument(String folderId, boolean toggle) {
getPresenter().onFolderToggleDocument(folderId,toggle);
}
->onClickThumbnailToggle -> toggleDocument.toggleDocument(docId,docItem.getPath(),!toggle)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(); <-
RestFolderRepository
@Override
public Observable<String> toggleDocument(String documnetId, String path, boolean toggle) {
return apiService.setDocumentAttribute(preferencesRepository.getToken(),documnetId,path,toggle?"isNew":"star")
.subscribeOn(Schedulers.io())
.onErrorReturn(throwable -> {
throwable.printStackTrace();
return null;
})
.map(aVoid -> "OK");
}
FolderCompanyFragment
@Override
public void onClickThumbnailToggle(DocItem docItem) {
getPresenter().onClickThumbnailToggle(docItem);
}
查詢服務器的所有方法都是類似的。我懷疑令牌的生命週期有什麼問題,但是如何解決這個問題。我希望有人能幫助我提供建議。如果有什麼不清楚的地方,請問我。
請,我需要一些想法,一些贊成,一些幫助! –