How do I get the photo stream using the Microsoft Graph Javascript client?
I'm also receiving this empty error when attempting to pull the users photo as a 'signed-in user'.
I'm using the below function where token is a valid OAuth token and the url is '/me/photo/$value':
const azureRequest = async (token, url) => {
const client = graph.Client.init({
authProvider: (done) => {
done(null, token);
},
});
try {
const result = await client
.api(url)
.get();
console.log(result);
return result;
} catch (err) {
console.error(err);
}
};
However, when removing the $value from the url and just pull the metadata, I'm able to pull it just fine.
{ '@odata.context':
'https: //graph.microsoft.com/v1.0/$metadata#users(\'{uid}\')/photo/$entity',
'@odata.mediaContentType': 'image/jpeg',
'@odata.mediaEtag': '"11FC69C2"',
id: '648X648',
height: 648,
width: 648
}
Originally posted by @technicallynick in https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/206#issuecomment-517765197
@MIchaelMainer So you're saying the request should look like this? I'm having a hard time finding some supporting documentation for the syntax. The doc you linked doesn't really go in to a lot of detail. I'm still getting the empty error with a 200 OK with the below configuration.
const graph = require('@microsoft/microsoft-graph-client');
const getAzureProfilePic = async (token) => {
const client = graph.Client.init({
authProvider: (done) => {
done(null, token);
},
});
try {
const result = await client
.api('/me/photo/$value')
.responseType(graph.ResponseType.BLOB)
.get();
console.log('ProfilePic::::', result);
return result;
} catch (err) {
console.error(err);
return err;
}
};
I also tried looking through the old beta github to find some other way of accomplishing it or some clue as to the syntax required.
@technicallynick can you tell us whether you are using browser or node version? if browser then can you give the details about the browser and it's version.
@krototype I'm using the node version.
npm 6.9.0 node v10.16.0 @microsoft/microsoft-graph-client v1.7.0
@technicallynick the blob response type is not supported for node (it is just supported for browser environment). You can use getStream to get the image data using node. This doc would help you with getStream.
As there has been no response on this issue for long, so we are closing this issue. Feel free to reopen the issue, if needed.