我使用的是oauth库中的hybridauth-3.7.1。https://github.com/hybridauth/hybridauth/releases
这个库工作得很好,所以我有以下几点:
<?php
require_once 'hybridauth-3.7.1/vendor/autoload.php';
$config = [
'callback' => 'my_callback_url',
'keys' => [
'id' => 'my_app_id',
'secret' => 'my_secret'
],
];
$adapter = new Hybridauth\Provider\Reddit( $config );
$adapter->authenticate();
$userProfile = $adapter->getUserProfile();
$photo = $userProfile->photoURL;现在,如果我尝试:
imagecreatefrompng($photo);我的日志返回:
imagecreatefrompng( https://styles.redditmedia.com/t5_55fo22/styles/profileIcon_bblqmk8klas71.png?width=256&amp;height=256&amp;crop=256:256,smart&amp;s=30a3bb6af945eadeaddb40271d2c0161ca82768d ): failed`因此,url在echo中正确返回,但从日志中可以看出,imagecreatefrompng添加了一个奇怪的&;
我也试过
imagecreatefrompng(urldecode($photo));和
$decoded_photo = urldecode($photo);
imagecreatefrompng($decoded_photo);两者都返回相同的上述错误日志。
但是,如果我手动键入url,它就可以正常工作。
imagecreatefrompng( 'https://styles.redditmedia.com/t5_55fo22/styles/profileIcon_bblqmk8klas71.png?width=256&height=256&crop=256:256,smart&s=30a3bb6af945eadeaddb40271d2c0161ca82768d' );如何让返回的图像url与imagecreatefrompng一起工作?
发布于 2021-10-25 23:57:07
问题是,当直接粘贴url时,如上一个示例所示,我没有意识到剪切和粘贴与实际源代码不同。
这意味着,尽管我复制的是&height=256...,但实际源代码中的内容是&=256...,因此,当我尝试imagecreatefrompng()时,它正在编码已经编码的&,从而导致&amp;
修复方法是更改$userProfile->photoUrl,如下所示。
$photo = htmlspecialchars_decode($userProfile->photoURL);
imagecreatefrompng($photo);https://stackoverflow.com/questions/69713172
复制相似问题