Получение токена oauth из Magento REST APIJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Получение токена oauth из Magento REST API

Сообщение Anonymous »

Мне нужна ваша помощь.
Мне нужно подключиться к моему магазину Magento с помощью REST, но у меня проблема с получением токена oauth.
Я сделал то, что было сказано в этом руководстве: gmartinezgil.wordpress. com/2013/08/05/using-the-magento-rest-api-in-java-with-scribe/
Мой код доступен здесь: https://www.dropbox.com/sh/zglzl9xsxcjrpid/ lGrZNYfRzG

Я работаю с Magento 1.8.1.0, используя Wampserver

Вот мой файл Main.java:

package foo;
import java.util.Scanner;

import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
/**
* @author jerry
*/
public final class Main {

/**
* @param args
*/
public static void main(String[] args) {
final String MAGENTO_API_KEY = "r0ntsryd0hamwmdnjezb8joun01c4h1s";
final String MAGENTO_API_SECRET = "czylgk8yxhkvrx141v1q9trx0iw4qbgt";
final String MAGENTO_REST_API_URL = "http://localhost/magento/api/rest/";
//final String MAGENTO_REST_API_URL = "http://localhost/magento/api.php?type=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();
}
}


Терминал отображает:

1.0
Magento's OAuth Workflow

Fetching the Request Token...
obtaining request token from http://`magentohost`/oauth/initiate/
setting oauth_callback to oob
generating signature...
using base64 encoder: CommonsCodec
base string is: POST&http%3A%2F%2F127.0.0.1%2Fmagento%2Foauth%2Finitiate%2F&oauth_callback%3Doob%26oauth_consumer_key%3Dr0ntsryd0hamwmdnjezb8joun01c4h1s%26oauth_nonce%3D2085598405%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1395911858%26oauth_version%3D1.0
signature is: edOifgJQfBg2QoM7ifVBWwvYj30=
appended additional OAuth parameters: { oauth_callback -> oob , oauth_signature -> edOifgJQfBg2QoM7ifVBWwvYj30= , oauth_version -> 1.0 , oauth_nonce -> 2085598405 , oauth_signature_method -> HMAC-SHA1 , oauth_consumer_key -> r0ntsryd0hamwmdnjezb8joun01c4h1s , oauth_timestamp -> 1395911858 }
using Http Header signature
sending request...
response status code: 404
response body:

404 Not Found

Not Found
The requested URL /magento/oauth/initiate/ was not found on this server.


Exception in thread "main" org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: '

404 Not Found

Not Found
The requested URL /magento/oauth/initiate/ was not found on this server.

'
at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:41)
at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:27)
at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:64)
at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:40)
at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:45)
at foo.Main.main(Main.java:35)


Подробнее здесь: https://stackoverflow.com/questions/227 ... o-rest-api
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Создайте новый API-интерфейс Magento Rest, чтобы получить список категорий в Magento.
    Anonymous » » в форуме Php
    0 Ответы
    41 Просмотры
    Последнее сообщение Anonymous
  • Magento REST API OAuth
    Anonymous » » в форуме Php
    0 Ответы
    13 Просмотры
    Последнее сообщение Anonymous
  • Настройте Magento REST API без OAuth
    Anonymous » » в форуме Php
    0 Ответы
    16 Просмотры
    Последнее сообщение Anonymous
  • Magento REST API OAuth для мобильного приложения
    Anonymous » » в форуме IOS
    0 Ответы
    13 Просмотры
    Последнее сообщение Anonymous
  • Magento — REST API/OAuth трехсторонняя аутентификация
    Anonymous » » в форуме Php
    0 Ответы
    7 Просмотры
    Последнее сообщение Anonymous

Вернуться в «JAVA»