我一直在努力使用Microsoft Graph获取登录用户的图像URL
<?php
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => "https://graph.microsoft.com/beta/me/photo/$value",
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => null,
CURLOPT_MAXREDIRS => 10,
CURLOPT_BINARYTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11",
CURLOPT_HTTPHEADER => array(
'authorization: Bearer EwBgA8l6BAAURSN/FHlDW5xN74t6GzbtsBBeBUYAATuF8OsoPq1qA+OJW6vNZu1QD6xsDHby7zwXDFBo7I2An/Y4J49AuEtWvb8v1yKDL+Kf1/iyZJ72jbo0wrDqB7Soxxzj14DBjDnHWLuxkrSLLhFcRNHyITxqbiHIRPI+3j0MpxlLiuIoSCxy+Y4fQqP7vJXolCwsyPCiAKAMJ8huEJYMr9Pd+npAur+q7S/fkoUQsxxtiJaipcaWIt8yzKhajqb7rcPMnoODK9wo/K8oFUGhIYvwhhW83/rp+IwIbwzU6RcWdeD7QyIAxmOb646GKrRO6M/pR9/sPqahitIuU1MPBD9GjLEz2F+orQGNeHhrdeX8BKyQSMvfhq7I62oDZgAACOzq1UE5lZRWMAKIXRflLOb0qnrJdEzwGUpMieK3rFjEhzsWQhy0+Rtss5Ch34z5chAevB4bqlJ0DKpm9IcpbDy75KuAwoR6kodRCyWO8NZrMYz/JGVnw19LTK3/lxYVdc9fRBwj6VtuB24+82T+TBnBIaaccy/g0vlhTIYzSTT5hA3EAL4GfLJ/PwhsJhg/1KH54bvT1TTaIOT7a56SUDOCPbcG2Mgdrviu/SQpfJtKDRjdvw70awc+xhAKa3M/99TuAKysiGUme/NZbkuxw1zfS7yydEh1C4M/uN81NNJQmPA5RKZbnH9AMJ/LAWF+uAetacAbz6xidnT/iI30GWpBCcV86wbTDJoSAuzbqtHQtnYC1sLBOhqqxucU8J/THkYNaJ9EZZlccWOQKbifjkpWPUAscFj+1ZlKw4v6BNFTSLf6nE8Htc5sKqz4eC6V3+faJs6gkz406Prf1jkAsvi+5VxkiusN0SncVU0usNEKGD8YymkXvJvr1i2KKbGMZAaMKYfO3GE+9lIMZj9+LZ94brIse9/ITfRLEHvx36v50r0Lr8NeNR/iEQKRjoRygkGXVQpmtgeBcO+LFVDPUIEkI29AI/jw1VkgHoWIZgszxi8x0YTYd7CY95yEXk+67ZrraIgPstPhZOMxRMHONQe3lQ440I4y15xRaFVdxxgApMxXWVpbrofiePCGiyvB1lok+T3VAEAsdld78uVgJituXZNbHvXAsig7lzQU0PmCICTUMf+kQd1RXWgC',
'Content-Type: image/jpg'
) ,
));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
以下是我的结果
{“ @ odata.context”:“ https://graph.microsoft.com/beta/ $ metadata#users('kayu2kshow%40hotmail.com')/ photo / $ entity”,“ @ odata.mediaContentType”:“ image / jpeg”, “ width”:96,“ height”:96,“ id”:“ 96X96”}
请,我如何使图像显示在网页上?
答案 0 :(得分:1)
您似乎没有打电话
https://graph.microsoft.com/beta/me/photo/$value
但是
https://graph.microsoft.com/beta/me/photo/
,因此仅接收个人资料图片的metadata。
PHP将尝试将字符串中的$value
解释为php变量。由于未设置$value
,因此该字符串不包含任何内容。
要告诉解释器您不想将$value
视为变量,需要转义$
字符。
尝试将行更改为:
CURLOPT_URL => "https://graph.microsoft.com/beta/me/photo/\$value"
然后发送正确的请求,您将收到图像数据(base64编码)
要显示Base64编码的图像,可以使用以下html代码:
<img src="data:image/jpeg;base64, {insertBase64EncodedData}"/>