簡體   English   中英

如何在 Android 中使用 REST API 調用 SharePoint 中的列表項?

[英]How to call List Item in SharePoint Using REST API in Android?

我想使用共享點休息 API 服務從 Android 調用以前我用來通過圖形 API 調用共享點 Web 服務但是從圖形 API 生成令牌時它在下面的 URL 中不支持,有沒有人對此有任何解決方案問題。

https://mysharepoint.sharepoint.com/sites/MySite/_api/web/lists/getbytitle ('公告')/Items

 JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, MSGRAPH_URL,
            parameters,new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            /* Successfully called graph, process data and send to UI */
            Log.d(TAG, "Response: " + response.toString());


            updateGraphUI(response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, "Error: " + error.toString());
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> headers = new HashMap<>();
            headers.put("Authorization", "Bearer " + authResult.getAccessToken());
            return headers;
        }
    };

    Log.d(TAG, "Adding HTTP GET to Queue, Request: " + request.toString());

    request.setRetryPolicy(new DefaultRetryPolicy(
            3000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    queue.add(request);

我已經嘗試過使用 MSAL 庫,但它不適用於此令牌。 更新:我曾經為 janrating 令牌調用圖形 api,但上面提到的 URL 出現 401 錯誤。

您正在調用 SharePoint API,因此您將需要 SharePoint 令牌而不是圖形令牌。 這是兩個具有不同身份驗證的獨立 API。

要獲取 SharePoint 令牌,您需要在 SharePoint 本身中注冊一個應用程序,或者使用用戶名 + 密碼(如果在您的應用程序中可用)。

另見: https : //spshell.blogspot.com/2015/03/sharepoint-online-o365-oauth.html https://shareyourpoint.net/2017/01/25/operations-using-rest-in-sharepoint-在線授權/

對於 Graph,使用這樣的 URL 來獲取您的列表項:

https://graph.microsoft.com/v1.0/sites/ {site-id}/lists/{list-id}/items?expand=fields(select=Column1,Column2)

您可能需要先進行多次調用才能獲取站點 ID 和列表 ID。

https://docs.microsoft.com/en-us/graph/api/listitem-list?view=graph-rest-1.0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM