简体   繁体   English

如何在 Android 中使用 REST API 调用 SharePoint 中的列表项?

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

I'm want to consume share point rest API service to call from Android previously i use to call share point web service through the graph API but while generating token from graph API its not support in below URL, does any one have any solution about this problem.我想使用共享点休息 API 服务从 Android 调用以前我用来通过图形 API 调用共享点 Web 服务但是从图形 API 生成令牌时它在下面的 URL 中不支持,有没有人对此有任何解决方案问题。

https://mysharepoint.sharepoint.com/sites/MySite/_api/web/lists/getbytitle ('Announcements')/Items 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);

I already tried with MSAL library but its does not work with this token.我已经尝试过使用 MSAL 库,但它不适用于此令牌。 Update : i used to call graph api for janrating token but i got 401 error with this above mention URL.更新:我曾经为 janrating 令牌调用图形 api,但上面提到的 URL 出现 401 错误。

You are calling a SharePoint API, so you will need a SharePoint token instead of a Graph token.您正在调用 SharePoint API,因此您将需要 SharePoint 令牌而不是图形令牌。 These are two separate APIs with different authentications.这是两个具有不同身份验证的独立 API。

To get a SharePoint token you will need to register an App in SharePoint itself or use the users username + password if available in your app.要获取 SharePoint 令牌,您需要在 SharePoint 本身中注册一个应用程序,或者使用用户名 + 密码(如果在您的应用程序中可用)。

Also see: https://spshell.blogspot.com/2015/03/sharepoint-online-o365-oauth.html https://shareyourpoint.net/2017/01/25/operations-using-rest-in-sharepoint-online-authorization/另见: https : //spshell.blogspot.com/2015/03/sharepoint-online-o365-oauth.html https://shareyourpoint.net/2017/01/25/operations-using-rest-in-sharepoint-在线授权/

For Graph, use an URL like this to get your list items:对于 Graph,使用这样的 URL 来获取您的列表项:

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

You will probably need to do several calls to get your site ID and list ID first.您可能需要先进行多次调用才能获取站点 ID 和列表 ID。

https://docs.microsoft.com/en-us/graph/api/listitem-list?view=graph-rest-1.0 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