首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ShopifySharp .Net库中正确获取访问令牌?

如何在ShopifySharp .Net库中正确获取访问令牌?
EN

Stack Overflow用户
提问于 2018-03-28 00:02:29
回答 2查看 2.5K关注 0票数 1

我使用https://github.com/nozzlegear/ShopifySharp .Net库来使用Shopify Api。我刚刚创建了dev webshop,我想测试一些GET方法。在文档中我看到了下面的代码:

代码语言:javascript
复制
string code = Request.QueryString["code"];
string myShopifyUrl = Request.QueryString["shop"];

string accessToken = await AuthorizationService.Authorize(code, myShopifyUrl, shopifyApiKey, shopifySecretKey); 

我理解的所有参数,除了第一,这是什么代码,我应该从哪里获得它??谢谢

EN

回答 2

Stack Overflow用户

发布于 2018-03-28 13:25:39

这基本上是授权代码

它是关于"OAuth"的概念的

参考:https://help.shopify.com/api/getting-started/authentication/oauth

票数 1
EN

Stack Overflow用户

发布于 2018-03-28 13:23:50

您应该在您的控制器中创建一个方法,它将接收来自Shopify的回调:

代码语言:javascript
复制
public ActionResult Callback(string code, string shop) {
    string accessToken = await AuthorizationService.Authorize(code, myShopifyUrl, shopifyApiKey, shopifySecretKey); 
}

然后在构建授权URL时,您应该将变量redirectUrl设置为上面的方法:

代码语言:javascript
复制
//This is the user's store URL.
string usersMyShopifyUrl = "https://example.myshopify.com";

// A URL to redirect the user to after they've confirmed app installation.
// This URL is required, and must be listed in your app's settings in your Shopify app dashboard.
// It's case-sensitive too!
string redirectUrl = "https://example.com/my/redirect/url";

//An array of the Shopify access scopes your application needs to run.
var scopes = new List<AuthorizationScope>()
{
    AuthorizationScope.ReadCustomers,
    AuthorizationScope.WriteCustomers
};

//Or, use an array of string permissions
var scopes = new List<string>()
{
    "read_customers",
    "write_customers"
}

//All AuthorizationService methods are static.
string authUrl = AuthorizationService.BuildAuthorizationUrl(scopes, usersMyShopifyUrl, shopifyApiKey, redirectUrl);

一旦用户将被重定向到授权URL,它将打开购物页面,用户将能够安装应用程序。然后,Shopify会使用codeshop参数将他重定向到您的回调方法

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49517603

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档