I want to call this API -> /_api/SP.UserProfiles.PeopleManager/GetMyProperties
from SharePoint provider hosted app, but whenever I'm calling this API what I got is 403 forbidden issue.
Here is my code
try
{
////retrieve current user profile details
Uri targetWeb = new Uri(Request.QueryString["SPHostUrl"]);
string targetRealm = TokenHelper.GetRealmFromTargetUrl(targetWeb);
var responseToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, targetWeb.Authority, targetRealm);
HttpWebRequest request = HttpWebRequest.CreateHttp(String.Format("{0}/_api/SP.UserProfiles.PeopleManager/GetMyProperties", Request["SPHostUrl"].Substring(0, 8 + Request["SPHostUrl"].Substring(8).IndexOf("/"))));
request.Accept = "application/json;odata=verbose";
request.Headers.Add("Authorization", String.Format("{0} {1}", responseToken.TokenType, responseToken.AccessToken));
Stream s = request.GetResponse().GetResponseStream();
using (StreamReader sr = new StreamReader(s))
using (Newtonsoft.Json.JsonReader reader = new JsonTextReader(sr))
{
JsonSerializer serializer = new JsonSerializer();
// read the json from a stream
// json size doesn't matter because only a small piece is read at a time from the HTTP request
var p = serializer.Deserialize(reader);
}
}
catch (Exception ex){}
Thanks for the help!