Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I would like to retrieve all the profile pictures of all the people in my org. How would I do that?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

If you have access to the REST API, then you can use the following python code:

import json
import requests

query = "SELECT+id,+FullPhotoUrl,+LastName+FROM+User"
query_url = 'https://na5.salesforce.com/services/data/v26.0/query/?q='
#access_token would be the access token retrieved from the OAuth process.
headers = {'Authorization': 'Bearer ' + access_token}

#get list of all users (id, photo url, and last name)
r = requests.get(query_url + query, headers=headers)
if r.status_code != 200:
    print r.content
else:
    resp = json.loads(r.content)
    print resp.get('records')
    #for each user in the result set
    for user in resp.get('records'):
        photo_url = user.get('FullPhotoUrl')
        r = requests.get(photo_url, headers=headers)
        print r.status_code
        if r.status_code == 200:
            filename = '/jmm/pics/{}.jpg'.format(user.get('LastName'))
            chunk_size = 500
            #download the image and save it to your harddrive
            with open(filename, 'wb') as fd:
                for chunk in r.iter_content(chunk_size):
                    fd.write(chunk)
        else:
            print 'head between your knees we\'re all gonna die!'
            print r.status_code
            print r.content
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.