I am trying to get user's blog post (newsfeed blog posts) which are located on different web application and show them within a web part by using JavaScript and REST API.
I use SP.RequestExecutor to make a cross domain request. My code is as follows. I have tested the query in IE and it worked perfectly. But when I run the code it generates
Invalid field or parameter requestInfo.url
function GetBlogPosts() {
var url1= "http://temp.com/personal/username/blog/_api/web/lists/getbytitle('Posts')/items?$select=Title,Id,Created"; var executor = new SP.RequestExecutor(_spPageContextInfo.webAbsoluteUrl); executor.executeAsync({ url: url1, method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function (data, textStatus, xhr) { alert("ok"); }, error: function (xhr, textStatus, errorThrown) { alert("error: " + JSON.stringify(xhr)); } });
}
$function() {
var scriptbase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.RequestExecutor.js", GetBlogPosts);
});
I think the error occurs in SP.RequestExecutor.js
1. I don't use apps, it is a usual JavaScript file.
2. I have installed all cumulative updates on my dev machine.
3. The query works in IE and Chrome when I enter it in address bar.
I have debugged the code in SP.RequestExecutor and it goes into this if-clause
if(SP.RequestExecutor.$O(a.url).toLowerCase()!==SP.RequestExecutor.$O(this.$A_0).toLowerCase())
throw SP.RequestExecutorUtility.$G("requestInfo.url");
it seems that it compares the url of the site that the Web Part has been installed and the url of the web application that the blog post of the users is located.