Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Graph Explorer Sample Data via REST</title>
</head>
<body>
  <img id="person" />
</body>
</html>
 
// Simple demo showing method for using Graph Explorer sample
// data via REST. Related blog post:
// https://dev.to/toddanglin/using-graph-explorer-to-get-sample-data-via-rest-2hah
async function getGraphData(){
  const options = {
    headers: {
        'Authorization':'Bearer {token:https://graph.microsoft.com/}'
     }
  }
  const proxyUrl = 'https://proxy.apisandbox.msdn.microsoft.com/svc';
  const graphUrl = 'https://graph.microsoft.com/v1.0/me/photo/$value';
  const url = `${proxyUrl}?url=${encodeURI(graphUrl)}`;
  console.log(url);
  const response = await fetch(url, options);
  const blob = await response.blob(); // Necessary for handling image data
  return blob;
}
let data = getGraphData()
  .then(d => {
    // Read the image blob data and assign as source to image element
    const reader = new FileReader() ;
    reader.onload = function(){ 
      const img = document.querySelector('#person');
      img.src = this.result;
    } ;
    reader.readAsDataURL(d) ;
  });
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers