【问题标题】:How to send a search request using OneDrive SDK for Android如何使用 OneDrive SDK for Android 发送搜索请求
【发布时间】:2015-04-27 01:38:39
【问题描述】:

我非常想了解如何使用适用于 Android 的 OneDrive SDK。 示例应用程序仅描述拾取、保存或探索。 我已经实现了此处可用的资源管理器: https://github.com/OneDrive/onedrive-explorer-android

最后,我有这样的代码:

final IOneDriveService oneDriveService = oneDriveHelper.getOneDriveService();
final Callback<Item> itemCallback = getItemCallback(app);
oneDriveService.getItemId(mItemId, mQueryOptions, itemCallback);

在哪里

mItemId="root";

我尝试通过这样做来更改 mQueryOptions

mQueryOptions.put("q", "myKeyWord");

没有成功(它只是列出根目录)

我尝试将 mItemId 替换为:

"root:/view.search"

没有任何成功。

http://onedrive.github.io/items/search.htm

【问题讨论】:

    标签: java android rest httprequest onedrive


    【解决方案1】:

    好吧,我终于明白这一切是如何运作的了。

    因此,由于 ApiExplorer 只是一个示例,我们需要在其中手动添加更多功能。

    在名为 onedriveaccess 的模块中,转到包 com.microsoft.onedriveaccess.model 并添加以下文件 ItemList.java

    package com.microsoft.onedriveaccess.model;
    
    import com.google.gson.annotations.SerializedName;
    import java.util.List;
    
    public class ItemList {
        @SerializedName("value")
        public List<Item> itemList;
    }
    

    然后在com.microsoft.onedriveaccess.IOneDriveService.java中,添加如下代码:

    @GET("/v1.0/drive/{item-id}/view.search")
    @Headers("Accept: application/json")
    void searchForItemId(@Path("item-id") final String itemId,
            @QueryMap    Map<String, String> options,
            final Callback<ItemList> itemCallback);
    

    现在我们可以生成如下搜索查询:

      /**
     * The query option to have the OneDrive service expand out results of navigation properties
     */
    private static final String EXPAND_QUERY_OPTION_NAME = "expand";
    
    /**
     * Expansion options to get all children, thumbnails of children, and thumbnails
     */
    private static final String EXPAND_OPTIONS_FOR_CHILDREN_AND_THUMBNAILS = "children(select=id, name)";
    
    
    private final Map<String, String> mQueryOptions = new HashMap<>();
    
    
    private Callback<ItemList> getItemsCallback(final Context context) {
        return new OneDriveDefaultCallback<ItemList>(context) {
            @Override
            public void success(final ItemList items, final Response response) {
                //mItem = items.itemList.get(0);
    
                //Do what you want to do
    
                for(Item item: items.itemList){
                  Log.v(TAG, "array:"+item.Id+"--- "+item.Name);
                }
            }
    
            @Override
            public void failure(final RetrofitError error) {
    
                //Log.v(TAG, "Item Lookup Error: " + mItemId);
    
            }
        };
    }
    
    
    public void searchQuery(String query){
        mQueryOptions.put(EXPAND_QUERY_OPTION_NAME, EXPAND_OPTIONS_FOR_CHILDREN_AND_THUMBNAILS);
        mQueryOptions.put("q", query);
    
        final IOneDriveService oneDriveService = oneDriveHelper.getOneDriveService();
        final Callback<ItemList> itemCallback = getItemsCallback(app);
        oneDriveService.searchForItemId(mItemId, mQueryOptions, itemCallback);
    
    }
    

    【讨论】:

      猜你喜欢
      • 2012-09-09
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      相关资源
      最近更新 更多