I want to get the ID of the current user using REST API : this is teh function :
function ReturnIDUser(url) {
//Url should be _spPageContextInfo.webAbsoluteUrl
// var item = getListItems(url, listName, customquery, '', '');
//ExecuteOrDelayUntilScriptLoaded(Start, "sp.js");
var Result = null;
$.ajax({
url:url+"/_api/sp.userprofiles.peoplemanager/getmyproperties",
type: "GET",
headers: { "Accept": "application/json;odata=verbose" },
success: function (data) {
Result = data.d;
////get login name
//var loginName = Result.LoginName.split('|')[1];
//alert(loginName);
////get display name
//alert(Result.Title);
//
},
async: false,
error: function (data) {
alert("failure");
}
});
return Result.Id;
}
but it's always : error , this is the error:
responseText "{\"error\":{\"code\":\"-1, System.InvalidProgramException\",\"message\":{\"lang\":\"en-US\",\"value\"
:\"Common Language Runtime detected an invalid program.\"},\"innererror\":{\"message\":\"Common Language Runtime detected an invalid program.
\",\"type\":\"System.InvalidProgramException\",\"stacktrace\":\" at Microsoft.Office.Server.UserProfiles.PeopleManager.GetMyProperties()\\r\\n
at Microsoft.Office.Server.UserProfiles.PeopleManagerServerStub.InvokeMethod(Object target, String methodName, ClientValueCollection xmlargs,
ProxyContext proxyContext, Boolean& isVoid)\\r\\n at Microsoft.SharePoint.Client.ServerStub.InvokeMethodWithMonitoredScope(Object target, String methodName,
ClientValueCollection args, ProxyContext proxyContext, Boolean& isVoid)\\r\\n
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.InvokeMethod(Boolean mainRequestPath, Object value, ServerStub serverProxy, EdmParserNode node,
Boolean resourceEndpoint, MethodInformation methodInfo, Boolean isExtensionMethod, Boolean isIndexerMethod)\\r\\n
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.GetObjectFromPathMember(Boolean mainRequestPath, String path, Object value, EdmParserNode node,
Boolean resourceEndpoint, MethodInformation& methodInfo)\\r\\n
at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.GetObjectFromPath(Boolean mainRequestPath, String path, String pathForErrorMessage)\\r\\n at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.Process()\\r\\n at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.ProcessRequest()\\r\\n
at Microsoft.SharePoint.Client.Rest.RestService.ProcessQuery(Stream inputStream, IList`1 pendingDisposableContainer)\"}}}"
0 commentaires:
Enregistrer un commentaire