mobile-buy-sdk-android失败,出现错误com.shopify.buy3.GraphHttpError
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mobile-buy-sdk-android失败,出现错误com.shopify.buy3.GraphHttpError相关的知识,希望对你有一定的参考价值。
下面是代码和错误消息
错误信息:
“错误com.shopify.buy3.GraphHttpError:HTTP 403 Forbidden”
403错误表示我没有正确验证请求,我在这里做错了什么?代码
OkHttpClient httpClient = new OkHttpClient.Builder()
.addNetworkInterceptor(new HttpLoggingInterceptor())
.build();
GraphClient gl = GraphClient.builder(this)
.shopDomain("<shop name>.myshopify.com")
.accessToken("myAPIKey")
.httpClient(httpClient)
.httpCache(new File(getApplicationContext().getCacheDir(), "/http"), 10 * 1024 * 1024)
.defaultHttpCachePolicy(HttpCachePolicy.CACHE_FIRST.expireAfter(5, TimeUnit.MINUTES)) // cached response valid by default for 5 minutes
.build();
Storefront.QueryRootQuery query = Storefront.query(new Storefront.QueryRootQueryDefinition() {
@Override public void define(final Storefront.QueryRootQuery rootQueryBuilder) {
rootQueryBuilder.shop(new Storefront.ShopQueryDefinition() {
@Override public void define(final Storefront.ShopQuery shopQueryBuilder) {
shopQueryBuilder.privacyPolicy(new Storefront.ShopPolicyQueryDefinition() {
@Override
public void define(final Storefront.ShopPolicyQuery policyQueryBuilder) {
policyQueryBuilder.body();
policyQueryBuilder.url();
policyQueryBuilder.title();
}
});
}
});
}
});
QueryGraphCall call = cl.queryGraph(query);
call.enqueue(new GraphCall.Callback<Storefront.QueryRoot>() {
@Override
public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response) {
String body = response.data().getShop().getPrivacyPolicy().getBody();
Log.v(TAG,"boby : " + body);
}
@Override
public void onFailure(@NonNull GraphError error) {
Log.v(TAG,"error " + error.toString());
}
});
答案
HTTP 403禁止
在您对Shopify的私人应用程序进行身份验证之前,您需要从要与应用程序连接的商店的Shopify管理员生成所需的凭据。
如果要使用Storefront API,请选择“允许此应用程序使用Storefront API访问店面数据”。这将生成Storefront访问令牌。
以上是关于mobile-buy-sdk-android失败,出现错误com.shopify.buy3.GraphHttpError的主要内容,如果未能解决你的问题,请参考以下文章