【问题标题】:OAuth Class not found, Magento cpanel in php file找不到 OAuth 类,php 文件中的 Magento cpanel
【发布时间】:2016-09-21 17:31:53
【问题描述】:

我已经为 oauth 安装了 php 扩展并将其添加到 php.ini 文件中。尽管当我尝试访问 OAuth 时,它给了我致命错误,因为找不到 OAuth 类。 我在 php.ini 文件中添加了类似 extension=oauth.so 的行。

错误日志

PHP 致命错误:在第 8 行的 /home/artcon/public_html/devsource/webservice/getCategories.php 中找不到类“OAuth”

代码:

<?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);
}

请帮忙

【问题讨论】:

  • 请添加示例代码和错误日志
  • @MateenMomin 我已经编辑了帖子。看那个。谢谢

标签: php magento oauth cpanel


【解决方案1】:

该错误表示未找到 OAuthClass,这意味着未找到您的 php 脚本所需的 php 类。

您在 php.ini 中所做的是启用 php OAuth 扩展。即使在 php 脚本中使用了 php 类并且该类未在任何地方定义时启用了扩展,您也可能会遇到 php 致命错误。

在 php.ini 中添加该行后,您是否重新启动了您的网络服务器(apache/nginx)?如果您刚刚添加它而没有重新启动,则更改无效。如果您使用 nginx,请使用 service httpd restart (centos) 或 service apache2 restart (ubuntu/debian) 或 service nginx restart 并查看它的运行方式。

【讨论】:

    猜你喜欢
    • 2017-09-20
    • 1970-01-01
    • 2018-04-10
    • 2016-07-22
    • 2017-04-27
    • 2016-04-30
    • 2019-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多