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





20 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
  7. Learned a lot of new things from your post! Good creation and HATS OFF to the creativity of your mind.
    Very interesting and useful about salesforce apex
    Best Salesforce training in Gurgaon



    ReplyDelete
  8. DIAC is offering Salesforce.com Training with on admin, developer, salesforce lightening, crm. Call @ +919310096831 for details on course fees, syllabus, placement facilities, batch timings, course duration.

    ReplyDelete
  9. The information which you have provided is very good. It is very useful who is looking for salesforce Online Training

    ReplyDelete
  10. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

    salesforce crm online training

    ReplyDelete
  11. Thanks for sharing valuable information and it is useful for onlineitguru provides the best salesforce Online course Hyderabad

    ReplyDelete