Ad

Mobile-buy-sdk-android Fails With Error Com.shopify.buy3.GraphHttpError

- 1 answer


Below is the code and error message

Error Message:

"error com.shopify.buy3.GraphHttpError: HTTP 403 Forbidden "

403 error indicates that I am not properly authenticating the request, What am I doing wrong here? The code

 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());
        }
    });
Ad

Answer

HTTP 403 Forbidden

Read Private authentication

Before you can authenticate a private application to Shopify, you need to generate the required credentials from the Shopify admin of the store that you want to connect with your application.

If you want to use the Storefront API, then select Allow this app to access your storefront data using the Storefront API. This will generate a Storefront access token.

Ad
source: stackoverflow.com
Ad