找不到OAuth类,Magento cpanel在php文件中

I have already installed php extension for oauth and added it into the php.ini file.Although when i tried to access the OAuth it gives me fatal error as OAuth class not found. I have added line like extension=oauth.so in php.ini file.

Error Log

PHP Fatal error: Class 'OAuth' not found in /home/artcon/public_html/devsource/webservice/getCategories.php on line 8

Code :

<?php
$callbackUrl = "http://yourhost/oauth_admin.php";
$temporaryCredentialsRequestUrl = "http://yourhost/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://yourhost/admin/oAuth_authorize';
$accessTokenRequestUrl = 'http://yourhost/oauth/token';
$apiUrl = 'http://yourhost/api/rest';
$consumerKey = 'yourconsumerkey';
$consumerSecret = 'yourconsumersecret';

session_start();
if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
    $_SESSION['state'] = 0;
}
try {
    $authType = ($_SESSION['state'] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
    $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
    $oauthClient->enableDebug();

    if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
        $requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
        $_SESSION['secret'] = $requestToken['oauth_token_secret'];
        $_SESSION['state'] = 1;
        header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']);
        exit;
    } else if ($_SESSION['state'] == 1) {
        $oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']);
        $accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
        $_SESSION['state'] = 2;
        $_SESSION['token'] = $accessToken['oauth_token'];
        $_SESSION['secret'] = $accessToken['oauth_token_secret'];
        header('Location: ' . $callbackUrl);
        exit;
    } else {
        $oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);

        $resourceUrl = "$apiUrl/products";
        $oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json'));
        $productsList = json_decode($oauthClient->getLastResponse());
        print_r($productsList);
    }
} catch (OAuthException $e) {
    print_r($e->getMessage());
    echo "&lt;br/&gt;";
    print_r($e->lastResponse);
}

Please help

duanhu7400
duanhu7400 我编辑了这篇文章。看那个。谢谢
4 年多之前 回复
douweida2669
douweida2669 添加示例代码和错误日志
4 年多之前 回复

1个回答



错误说未找到OAuthClass,这意味着找不到php脚本所需的php类。</ p >

您在php.ini中所做的是启用php OAuth扩展。 即使你在PHP脚本中使用php类并且该类没有在任何地方定义,你也可能会得到一个php致命错误,即使启用了扩展名。</ p>

你重新启动了你的web服务器(apache) / nginx)在php.ini中添加该行后? 如果刚刚重新添加它,则更改无效。 使用服务httpd restart(centos)或service apache2 restart(ubuntu / debian)或服务nginx restart如果你使用nginx并查看它是如何播放的。</ p>
</ div>

展开原文

原文

The error says that the OAuthClass is not found which means a php class that is required by you php scripts is not found.

What you did in php.ini is to enable php OAuth extension. Even if the extension is enabled if you do use a php class in a php script and that class is not defined anytwhere you might get a php fatal error.

Did you restart your webserver (apache/nginx) after adding that line in php.ini? If you have just added it without restart, the changes are not in effect. Use a service httpd restart (centos) or service apache2 restart (ubuntu/debian) or a service nginx restart if you use nginx and see how it plays.

douchan6512
douchan6512 没问题。 我很高兴你解决了!
4 年多之前 回复
drsxobip501258
drsxobip501258 我已经解决了。 但感谢您的回应。
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐