以下是代码和错误消息
错误讯息:
“错误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());
}
});
答案 0 :(得分:0)
HTTP 403 Forbidden
在您对Shopify的私人应用程序进行身份验证之前,您需要从要与您的应用程序连接的商店的Shopify管理员生成所需的凭据。
如果要使用Storefront API,请选择“允许此应用程序” 使用Storefront API访问店面数据。这将 生成店面访问令牌。