Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento Rest API为产品重新调整404页面_Api_Rest_Magento - Fatal编程技术网

Magento Rest API为产品重新调整404页面

Magento Rest API为产品重新调整404页面,api,rest,magento,Api,Rest,Magento,我已经安装/配置了Magento 1.9。在我的本地Ubuntu14机器上使用CE,方法是遵循以下指南。我已经将我的Magento基地设置为 然后我尝试使用Scribe从Java访问API。这是我现在掌握的代码: public final class MagentoAuth { /** * @param args */ public static void main(String[] args) { final String MAGENTO_

我已经安装/配置了Magento 1.9。在我的本地Ubuntu14机器上使用CE,方法是遵循以下指南。我已经将我的Magento基地设置为

然后我尝试使用Scribe从Java访问API。这是我现在掌握的代码:

public final class MagentoAuth {

    /**
     * @param args
     */
    public static void main(String[] args) {
        final String MAGENTO_API_KEY = "abc";
        final String MAGENTO_API_SECRET = "xyz";
        final String MAGENTO_REST_API_URL = "http://localhost/api/rest";

        // three-legged oauth
        OAuthService service = new ServiceBuilder()
        .provider(MagentoThreeLeggedOAuth.class)
        .apiKey(MAGENTO_API_KEY)
        .apiSecret(MAGENTO_API_SECRET)
        .debug()
        .build();

        System.out.println("" + service.getVersion());
        Scanner in = new Scanner(System.in);
        System.out.println("Magento's OAuth Workflow");
        System.out.println();

        // Obtain the Request Token
        System.out.println("Fetching the Request Token...");
        Token requestToken = service.getRequestToken();
        System.out.println("Got the Request Token!");
        System.out.println();

        System.out.println("Fetching the Authorization URL...");
        String authorizationUrl = service.getAuthorizationUrl(requestToken);
        System.out.println("Got the Authorization URL!");
        System.out.println("Now go and authorize Main here:");
        System.out.println(authorizationUrl);
        System.out.println("And paste the authorization code here");
        System.out.print(">>");

        Verifier verifier = new Verifier(in.nextLine());
        System.out.println();
        System.out.println("Trading the Request Token for an Access Token...");

        Token accessToken = service.getAccessToken(requestToken, verifier);
        System.out.println("Got the Access Token!");
        System.out.println("(if your curious it looks like this: "
                + accessToken + " )");
        System.out.println();

        OAuthRequest request = new OAuthRequest(Verb.GET, MAGENTO_REST_API_URL+ "/products?limit=2");
        service.signRequest(accessToken, request);

        Response response = request.send();
        System.out.println();
        System.out.println(response.getCode());
        System.out.println(response.getBody());
        System.out.println();
    }
}
当我运行这个程序时,我能够成功地获取令牌,然后从Magento管理面板进行验证。但是,当我粘贴令牌时,会出现以下错误:

404
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /api/rest/products was not found on this server.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at localhost Port 80</address>
</body></html>
现在,当我尝试运行代码时,它甚至在获取令牌之前就失败了,并出现以下错误:

response status code: 403
response body: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /var/www/html/index.php
on this server.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at localhost Port 80</address>
</body></html>
响应状态代码:403
答复机构:
403禁止
被禁止的
您没有访问/var/www/html/index.php的权限
在这个服务器上


本地主机端口80上的Apache/2.4.7(Ubuntu)服务器

谢谢。

确保使用选项-多视图

有什么建议吗?有吗?是的,在安装Magento之前,您需要先安装示例数据。您可以登录到Magento管理员并查看前端吗?前端是否正常工作(即查看产品、登录、签出等)看起来您的Magento设置不正确。@DavidTay前端工作正常。我可以以管理员身份登录、查看订单、目录等。我还尝试以普通客户的身份下订单,效果良好。请确保在Magento安装的根目录中有api.php。另外,请确保您有一个标准的Magento.htaccess和RewriteRule^api/restapi.php?type=rest[QSA,L]。我两个都有。到目前为止,我一直在尝试将基本url设置为“”,它给出了一个正常的404错误。但是,如果我将基本url更改为“”,它将返回一个类似于magento主页的html页面,但有一条消息显示“OOPS!找不到404页。您可能希望再次检查该url或转到我们的主页。”我的Magento安装目录是/var/www/html,我在.htaccess中有正确的配置。你是我的新好友。
## you can put here your magento root folder
## path relative to web root

    RewriteBase /var/www/html/
response status code: 403
response body: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /var/www/html/index.php
on this server.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at localhost Port 80</address>
</body></html>