门德利分页

时间:2014-08-29 19:15:15

标签: asp.net mendeley

  1. SciTS Mendeley集团目前有1205项资源(引用)。但是,无论我们如何调用API的“getDocuments”方法,我们只获得前1000个资源。我们需要传递一个特定参数来获取完整的资源列表吗?或者有没有办法进行后续调用,使第一次调用不返回数据页?

        string grantType = "client_credentials";
        string applicationID = "id";
        string clientsecret = "XXXXXXX";
        string redirecturi = "*******";
        string url = "https://api-oauth2.mendeley.com/oauth/token";
        string view = "all";
        string group_id = "f7c0e437-f68b-34df-83c7-2877147ba8f9";
        HttpWebResponse response = null;
    
        try
        {
            // Create the data to send
            StringBuilder data = new StringBuilder();
            data.Append("client_id=" + Uri.EscapeDataString(applicationID));
            data.Append("&client_secret=" + Uri.EscapeDataString(clientsecret));
            data.Append("&redirect_uri=" + Uri.EscapeDataString(redirecturi));
            data.Append("&grant_type=" + Uri.EscapeDataString(grantType));
    
            data.Append("&response_type=" + Uri.EscapeDataString("code"));
            data.Append("&scope=" + Uri.EscapeDataString("all"));
    
            byte[] byteArray = Encoding.UTF8.GetBytes(data.ToString());
    
            // Setup the Request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
    
            // Write data
            Stream postStream = request.GetRequestStream();
            postStream.Write(byteArray, 0, byteArray.Length);
            postStream.Close();
    
            // Send Request & Get Response
            response = (HttpWebResponse)request.GetResponse();
            string accessToken;
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                // Get the Response Stream
                string json = reader.ReadLine();
                Console.WriteLine(json);
    
                // Retrieve and Return the Access Token
                JavaScriptSerializer ser = new JavaScriptSerializer();
                Dictionary<string, object> x = (Dictionary<string, object>)ser.DeserializeObject(json);
                accessToken = x["access_token"].ToString();
            }
            // Console.WriteLine("Access TOken"+ accessToken);
    
            var apiUrl = "https://api-oauth2.mendeley.com/oapi/documents/groups/3556001/docs/?details=true&items=1250";
    
            try
            {
                request = (HttpWebRequest)WebRequest.Create(apiUrl);
                request.Method = "GET";
                request.Headers.Add("Authorization", "Bearer " + accessToken);
    
                request.Host = "api-oauth2.mendeley.com";
    
                response = (HttpWebResponse)request.GetResponse();
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    // Get the Response Stream
                    string json = reader.ReadLine();
                    Console.WriteLine(json);
                    //need this to import documents
    
                }
                              }
            catch (WebException ex1)
            {
    
                Console.WriteLine("Access TOken exception" + ex1.Message);
            }
    
    
        }
        catch (WebException e)
        {
    
            if (e.Response != null)
            {
                using (HttpWebResponse err = (HttpWebResponse)e.Response)
                {
                    Console.WriteLine("The server returned '{0}' with the status code '{1} ({2:d})'.",
                      err.StatusDescription, err.StatusCode, err.StatusCode);
                }
            }
        }
    

1 个答案:

答案 0 :(得分:0)

返回的默认项目数限制为每页1000个。对于分页响应,您应该在响应中获得一些额外的字段;值得注意的是&#39; items_per_page&#39;,&#39; total_pages&#39;,&#39; total_results&#39;。

我怀疑你有两页要获得下一个结果,你需要追加&#39; page = 1&#39;。