Friday, May 25, 2012

User Photo Not Visible On Force.com Site From Rest API In Apex Salesforce


Hi All ,
I was accessing the photourl through force.com site !

"photo": {
        "largePhotoUrl": "https://instance_name/profilephoto/729D00000000BDV/F",
        "photoVersionId": "729D00000000BDV",
        "smallPhotoUrl": "https://instance_name/profilephoto/729D00000000BDV/T"
},

Now if we expose these photo url on visualforce page would render properly but if we try to get the same of public force.com site these photo url does not exist because session does not maintain .Images look like burst and does not show properly.

So what we can do , we can append either oauth_token or sessionid at the last of the photourl as a parameter. 
Let say our photo url is "largePhotoUrl": 

"https://instance_name/profilephoto/729D00000000BDV/F",

so we need to append the oauth_token like :



largePhotoUrl": "https://instance_name/profilephoto/729D00000000BDV/F'?oauth_token=00DV0000004RJpB!ARMAQFwrXxu7t6DAjWcseeWxXTo9UtSh4xZbrWJqHRnCulQ16yKqq97wIWIREdPtKfQ7BcFffyD9Y43MVBfa4hmHaPLfkT6C';
Now you can access the image as public with the help of oauth_token . Thanks





12 comments:

  1. There is better solution using chatter connect API.

    public String getUserPhotoURL(String UserId) {
    ConnectApi.Photo ph = ConnectApi.ChatterUsers.getPhoto(null, UserId);
    return ph.fullEmailPhotoUrl;
    }

    Read more in my blog:
    http://sforcenotes.blogspot.com/2015/10/solution-to-display-salesforce-user.html

    ReplyDelete
  2. Salesforce is the cloud based tool which is used by most of the professional who do CRM. Salesforce is the cost effective tool.
    salesforce training institute in chennai|salesforce training institutes in chennai|salesforce course in chennai

    ReplyDelete
  3. Nowadays, most of the businesses rely on cloud based CRM tool to power their business process. They want to access the business from anywhere and anytime. In such scenarios, salesforce CRM will ensure massive advantage to the business owners. Salesforce Training | Salesforce Training in Chennai

    ReplyDelete
  4. This blog having the details of Processes running. The way of runing is explained clearly. The content quality is really great. The full document is entirely amazing. Thank you very much for this blog.
    Hadoop Training in Chennai

    ReplyDelete
  5. This is Great and very useful advice with in this post. Thank you.
    mvc training in chennai

    ReplyDelete
  6. Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    iOS Training in Chennai

    ReplyDelete