How to get user profile image via API
I have been working to externalize information about my users on an RTC 3.0.1 system via API. When I make a call to https://<HOST>/jazz/oslc/ I get back a nice response that includes
<rtc_cm:User rdf:resource="https://<HOST>/jazz/oslc/users/_tKYZEArvEd-_CvlJWZEkGw">
<rtc_cm:userId>aaron</rtc_cm:userId>
<dc:title>Aaron</dc:title>
<rtc_cm:emailAddress>aaron@<HOST>.com</rtc_cm:emailAddress>
<rtc_cm:photo rdf:resource="https://<HOST>/jazz/resource/content/_xD8j4BV3EeKkj9-_5VhsPg"/>
<dc:modified>2012-10-13T20:51:31.293Z</dc:modified>
<rtc_cm:modifiedBy rdf:resource="https://<HOST>/jazz/oslc/users/_KGRY4CFWEdq-WY5y7lROQw"/>
</rtc_cm:User>
When I attempt to load the photo via its rdf:resource I first get a 400 back from the server and then get stuck with an HTML response (not image) that says
On the page there is also a link to "Download content" . Clicking that link seems to set a cookie in the environment that says its ok to load that image from there on out (or its being statically cached by the browser).
The question is, is there a way to programmatically get past this html intercept response and actually retrieve the image with out a user click.
The only thing I am noticing is that it appears the reference to the link in the response message is relative ( /resource/content/_asdfasdfasd versus my link which is https://<SERVER>/jazz/osls/resource/content/_asdfasdfasdf
The other thing that may be an issue is the referrer value obviously changes on the headers. Spoofing the referrer looks to be not a good thing.
so, is it possible to load the user photo programatically? If not, what is the use case where this user information is valuable.
|
Accepted answer
If you are writing a Jazz Plugin (e.g. a Dashboard Viewlet), you can use the following code to access a users profile (userId is the standard Jazz User ID that is used for the login as well, e.g. ADMIN):
getProfileImage: function(userId) {
var Util = com.ibm.team.dashboard.web.util.internal.Util;
var SERVICE_PHOTO_ID = "com.ibm.team.dashboard.viewlets.service.internal.members.IMemberPhotoService";
return Util.getServiceURL(SERVICE_PHOTO_ID, null, {userId: userId});
},
Ralph Schoon selected this answer as the correct answer
|
2 other answers
Ralph Schoon (63.5k●3●36●46)
| answered Oct 16 '12, 8:40 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Oct 16 '12, 9:03 a.m.
Hi, It should be possible using the plain java client libraries. The Eclipse user editor does it. I don't know how the REST API does it, but I have (untested) code that should do it for the Plain Java Client libraries.
Comments
Aaron Allsbrook
commented Oct 16 '12, 9:13 a.m.
Hi Ralph - Thanks for the response,
Although I would love to write it in java, I need to execute everything in javascript. Consequently I need the REST API.
Any other ideas?
|
Ralph Schoon (63.5k●3●36●46)
| answered Jul 25 '17, 3:25 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER See https://rsjazz.wordpress.com/2013/01/08/maintaing-user-photos-with-the-plain-java-client-libraries/
Comments
Lukas Steiger
commented Jul 25 '17, 3:32 a.m.
Thank you Ralph, but I'm unfortunately limited to JavaScript based solutions... The URI I get for the Photo is
Lukas Steiger
commented Jul 25 '17, 4:21 a.m.
And how do you get the ItemID of the user, without using RTC SDK? OSLC lacks the ability to query the itemID of the user, I only get the jazz ID
Lukas Steiger
commented Jul 25 '17, 6:48 a.m.
Thank you Ralph for your suggestion. I was unable to use the one you have suggested, but I found a service that accepts a userId. See my answer below....
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.
Comments
Tried some additional testing today with RTC 4. It appears to not have the security prevention intercept on it there. Consequently I am able to pull the images correctly in RTC 4.
Aaron, I am having the same issue trying to pull photos from RTC 4.0.1 through the API. I have tried two different methods. The one you show above, which is based on a resource ID of the photo, and this method, based on the itemId of the user:
https://SERVER:PORT/jazz/service/com.ibm.team.apt.internal.service.rest.IResourcePlanningRestService/workEnvironment?contributorId=USERITEMID
Unfortunately, I get the same results with both methods, the "you have found a direct link" error. Were you ever able to solve this?
Just tried a third method - same result:
https://SERVER:PORT/jts/users/photo/USERID
Have you ever found a solution on this?
I'm facing the same issue...