【发布时间】:2014-04-24 10:19:50
【问题描述】:
这是 sunil 非常新的使用 MAGENTO rest api。我必须创建一个应用程序才能使用 magento rest api 来检索库存、订单详细信息、创建产品、更新库存。但是我对如何使用 c# 从检索身份验证令牌到检索我们商店的所有详细信息来使用 magento api 有点困惑。请提供一些建议或一些示例 C# 代码。
下面我给出了我迄今为止尝试过的代码。但是错误给了我“远程服务器返回错误:(401)未经授权。”
var consumerKey = "xxxxxxxxxxxx"; var consumerSecret = "xxxxxxxxxxxx";
var uri = new Uri("http://enterprise-admin.user.magentotrial.com/oauth/initiate");
// Generate a signature
OAuthBase oAuth = new OAuthBase();
string nonce = oAuth.GenerateNonce();
string timeStamp = oAuth.GenerateTimeStamp();
string parameters;
string normalizedUrl;
string signature = oAuth.GenerateSignature(uri, consumerKey, consumerSecret,
String.Empty, String.Empty, "POST", timeStamp, nonce, OAuthBase.SignatureTypes.HMACSHA1,
out normalizedUrl, out parameters);
//signature = HttpUtility.UrlEncode(signature);
signature = System.Uri.EscapeUriString(signature);
StringBuilder requestUri = new StringBuilder(uri.ToString());
requestUri.AppendFormat("?oauth_consumer_key={0}&", consumerKey);
requestUri.AppendFormat("oauth_nonce={0}&", nonce);
requestUri.AppendFormat("oauth_timestamp={0}&", timeStamp);
requestUri.AppendFormat("oauth_signature_method={0}&", "HMAC-SHA1");
requestUri.AppendFormat("oauth_version={0}&", "1.0");
requestUri.AppendFormat("oauth_signature={0}", signature);
var request = (HttpWebRequest)WebRequest.Create(new Uri(requestUri.ToString()));
request.Method = WebRequestMethods.Http.Post;
var response = request.GetResponse();
【问题讨论】:
-
你成功了吗?您将 magento 代码 (PHP) 与 C# 集成!让我们知道您到目前为止尝试了什么?
-
我只是在研究如何做。经过大量搜索后,我从 magento 网站获得了 php 代码。我在 magento 企业版上创建了一个免费的模拟账户。得到消费者密钥和消费者密钥。我在这里停留了 2 天。无法在 c# 中编写代码以使用 magento rest api 服务。
-
你可以使用soap以及rest magento api。有关 magento api 的更多信息,您可以在下面的链接中找到 magentocommerce.com/api/rest/introduction.html@ViralShah api 意味着可以跨不同平台访问它的 php、#c 或 java。没关系。
-
我必须做rest api而不是soap。但是对于magento rest api,我现在尝试时遇到错误。有问题我正在给我的代码我尝试过的东西。
-
您正在将身份验证参数添加到 url,而它们需要位于 Authorization 标头中。 magentocommerce.com/api/rest/testing_rest_resources.html