PHP OAuth :: fetch()在第二次连续调用时返回错误请求

问题描述 投票:0回答:1

我正在使用OAuth1连接到Smugmug API,我有这个代码从他们的服务器检索专辑。

class SmugmugHelper
{
    private $oauth_client;

    public function __construct()
    {
        $this->oauth_client = new \OAuth("REPLACED_KEY", "KEPLACED_KEY");
        $this->oauth_client->setToken("REPLACED_KEY", "REPLACED_KEY");
    }

    public function getAlbum($node_id)
    {
        $url = "https://www.smugmug.com/api/v2/node/" . $node_id;
        $parameters = [];
        $method = 'GET';

        // this fetch always works
        $this->oauth_client->fetch($url, $parameters, $method, array('Accept' => 'application/json'));
        $response = $this->oauth_client->getLastResponse();
        $response = json_decode($response, true);

        $album_uri = $response['Response']['Node']['Uris']['Album']['Uri'];
        $url = "https://www.smugmug.com" . $album_uri;

        // this fetch doesn't work on prod but it does on local
        $this->oauth_client->fetch($url, $parameters, $method, array('Accept' => 'application/json'));
        $response = $this->oauth_client->getLastResponse();
        $response = json_decode($response, true);

        $album = $response['Response']['Album'];
        return $album;
    }
}

然后在我的控制器中我做

$smmHelper = new SmugmugHelper();
$album = $smmHelper->getAlbum('FXzQcV');

现在,当我尝试从那些ENDPOINTS中获取数据时,它在我的本地服务器中工作得很好,但是在我的prod服务器中只是第一次获取工作,但第二次没有。

我尝试跳过第一次获取并硬编码我从第一次获得的相同URL

...
// this fetch doesn't work on prod but it does on local
$this->oauth_client->fetch("Hardcoded URL", $parameters, $method, array('Accept' => 'application/json'));
...

它只能做一个电话。

我不知道还能做什么。

我的本地服务器是Apache2,PHP版本7.1.3,启用了OAuth扩展。

我的生产服务器由greengeeks.com托管,并且启用了支持OAuth扩展的PHP 7.1版。

如果有更多信息我可以提供。

php oauth
1个回答
0
投票

好吧,我想出来了。我的prod服务器在PHP v.7.0和OAuth扩展v.2.0.2上遇到了麻烦。

我尝试使用相同的PHP和扩展版本的另一台服务器,它就像一个魅力。

© www.soinside.com 2019 - 2024. All rights reserved.