Content API Sample

70 views
Skip to first unread message

Shaihulud

unread,
May 25, 2013, 12:45:54 PM5/25/13
to adwor...@googlegroups.com
Hi

i am trying to get to know more about the content api to retrieve informations like these https://developers.google.com/shopping-content/?hl=de

Ive found this developers guide for java https://developers.google.com/shopping-content/developers-guide-java#batching  but i have problems implementing it.

Ive included the maven dependencies as stated here http://code.google.com/p/google-api-java-client/wiki/Setup#Maven but it fails to resolve Classes like GoogleHeaders or AtomParser etc. anyway.

So im thinking either the documentation is not up to date in which case i would love to know if there is another code example somewhere. Or maybe the documentation is too old?
Or am i simply misunderstanding something?

Another example in any of the repositories or anywhere else would be great in either case.

I would really appreciate if somebody could shed some light into this

thx




Shaihulud

unread,
May 27, 2013, 5:23:28 AM5/27/13
to adwor...@googlegroups.com
Oki ive managed to get as far as to sending a request like this:

[code]
    @Override
    public void run() {
        namespaceDictionary = namespaceDictionary
                .set("", "http://www.w3.org/2005/Atom")
                .set("app", "http://www.w3.org/2007/app")
                .set("gd", "http://schemas.google.com/g/2005")
                // Try: for data quality maybe just insert https://content.googleapis.com/content/v1/54321/dataquality/98765
                .set("sc", "http://schemas.google.com/structuredcontent/2009")
                .set("scp", "http://schemas.google.com/structuredcontent/2009/products")
                .set("xml", "http://www.w3.org/XML/1998/namespace");
       
        errorNamespaceDictionary = errorNamespaceDictionary.set("", "http://schemas.google.com/g/2005");

        try {

             // create new transport
            HttpTransport transport = new NetHttpTransport();
            // ClientLogin
            ClientLogin authenticator = new ClientLogin();
            authenticator.transport = transport;
            authenticator.authTokenType = "structuredcontent";
            authenticator.username = "so...@email.de";
            authenticator.password = "somepassword";
           
            final ClientLogin.Response response = authenticator.authenticate();
           
            // create request factory
            httpRequestFactory = authenticator.transport.createRequestFactory(new HttpRequestInitializer() {
                @Override
                public void initialize(HttpRequest request) {
                    HttpHeaders headers = new HttpHeaders();
                    // authorize using clientLogin
                    headers.setAuthorization(response.auth);
                    request.setHeaders(headers);
                    request.setParser(new XmlObjectParser(namespaceDictionary));
                    response.initialize(request);
                }
            });
           
            List<Product> products = getProducts();
            for(Product product : products) {
                System.out.println(product.name);
            }
           
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }   

    private static List<Product> getProducts() throws IOException, HttpResponseException {
        String url = ROOT_URL + "322-413-9894" + "/items/products/schema";   // also tried the account id like this -> "3224139894"
        HttpRequest request = httpRequestFactory.buildGetRequest(new GenericUrl(url));
        ProductFeed feed = request.execute().parseAs(ProductFeed.class);
        return feed.entries;
    }
[/code]

The Problem now is that i get a "com.google.api.client.http.HttpResponseException: 403 Forbidden" or a "" saying that either error "<internalReason>Unknown customer-id in URL:" for 3224139894 or a 400 Bad Request "<location type='other'>customer-id</location><internalReason>Invalid customer id in URL</internalReason>" for 322-413-9894

Isnt the account id the customer id?

greetings

Shaihulud

unread,
May 27, 2013, 5:57:37 AM5/27/13
to adwor...@googlegroups.com
My mistake, ive used the a subaccount id. i thought this would work, but apparently i can just use my own account id.
Reply all
Reply to author
Forward
0 new messages