pythoncurlmicrosoft-graph-apiaddressbookvcf-vcard

Download all user profile images in Microsoft Graph using python and associate each one to the respective user on his vCard


I need to download all the user profile images on Microsoft Graph via Python and then, in order to complete the vCard, take each downloaded image and associate it with the respective user.

import requests

url="https:\\microsoft url token"
data = {
    "accept": 'application/json; charset=utf-8',
    "Content-Type": 'xxxx',
    "grant_type": 'xxxx',
    "client_id": "xxxx",
    'scope':'graph microsoft, this is an https address',
    "client_secret": "xxxx",
}
response=requests.post(url, data=data)

I receive an http 402 error and so i don't finally know how to retrieve the users profile image that I need


Solution

  • Your URL is not valid.

    To get data you may need to use a GET requests.get()

    This is what MS recommends:

    Method  Description
    GET     Read data from a resource.
    POST    Create a new resource, or perform an action.
    PATCH   Update a resource with new values.
    PUT     Replace a resource with a new one.
    DELETE  Remove a resource.
    

    If you can point me to the documentation or source where you got your code, I may be able to help.

    .

    I am guessing you may want something like this:

    import requests
    
    headers = {
        'accept': 'application/json; charset=utf-8',
        'client_secret': 'xxxx',
        'Content-Type': 'application/json',
        'grant_type': 'xxxx',
        'scope': 'graph microsoft, this is an https address',
        'client_secret': 'xxxx',
    }
    response = requests.get('https://microsoft.com', headers=headers)
    



    .