6 messages in com.googlegroups.google-base-data-apiRe: Problem with displaying in Google...| From | Sent On | Attachments |
|---|---|---|
| Black Eric | 09 Jul 2007 03:16 | |
| Jeff S | 10 Jul 2007 11:48 | |
| Black Eric | 10 Jul 2007 12:53 | |
| Black Eric | 10 Jul 2007 13:02 | |
| Trong | 20 Jul 2007 00:49 | |
| Black Eric | 20 Jul 2007 08:06 |
| Subject: | Re: Problem with displaying in Google Product Search![]() |
|---|---|
| From: | Black Eric (alex...@gmail.com) |
| Date: | 07/20/2007 08:06:03 AM |
| List: | com.googlegroups.google-base-data-api |
Hello, Trong,
Thanks for help, but I already read this pages. I wrote to Google Base support. They answer me that is Google Base internal temporary problem, and the try to fix it. Now leave only one variant - use bulk upload.
On Jul 20, 10:50 am, Trong <tron...@gmail.com> wrote:
Hi Black Eric,
I think you should read these topics in Google Base Help Center:
http://base.google.com/support/bin/answer.py?answer=45915&topic=9328
http://base.google.com/support/bin/answer.py?answer=37688
http://base.google.com/support/bin/answer.py?answer=37736
Please tell me if it works for you.
On Jul 11, 3:02 am, Black Eric <alex...@gmail.com> wrote:
Hello, Jeff S,
This my sources. In previous post I show xml that returned from Google
Base when I use this class. Items that I post by use this code
correctly displayed into Google Base, but not displayed into Google
Product Search. I take this sources
fromhttp://code.google.com/apis/base/samples/java/InsertExample.java. I
change there only xml.
package googlebase;
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; import java.util.StringTokenizer;
/** * * @author BlackEric */ public class Main {
/** * URL of the authenticated customer feed. */ private static final String ITEMS_FEED = "http://base.google.com/ base/feeds/items";
/** * Insert here the developer key obtained for an "installed application" at *http://code.google.com/apis/base/signup.html */ private static final String DEVELOPER_KEY = "";
/** * The data item we are going to insert, in XML/Atom format. */ private static final String DATA_ITEM = "<?xml version='1.0'?>\n"+ "<entry xmlns='http://www.w3.org/2005/Atom'xmlns:g='http:// base.google.com/ns/1.0'>\n"+ "<category scheme='http://base.google.com/categories/itemtypes' term='Products'/>\n"+ "<g:item_type type='text'>Products</g:item_type>\n"+ "<g:product_type> Software </g:product_type>\n"+ "<g:expiration_date type='dateTime'>2007-8-8T00:00:00.000Z</ g:expiration_date>\n"+ "<title type='text'>test</title>\n"+ "<content type='xhtml'>Test Upoad To Google Base</content>\n"+ "<link rel='alternate' type='text/html' href='http://mysite.com/ index.html?referrer=froogle&contractId=71704'/>\n"+ "<g:price>1.0</g:price>\n"+ "</entry>";
/**
* URL used for authenticating and obtaining an authentication
token.
* More details about how it works:
* <code>http://code.google.com/apis/accounts/
AuthForInstalledApps.html<code>
*/
private static final String AUTHENTICATION_URL =
"https://www.google.com/accounts/ClientLogin";
/**
* Fill in your Google Account email here. */ private static final String EMAIL = "....@gmail.com";
/** * Fill in your Google Account password here. */ private static final String PASSWORD = "";
/** * The main method constructs a <code>InsertExample</code> instance, obtains an * authorization token and posts a new item to Google Base. */ public static void main(String[] args) throws MalformedURLException, IOException { Main insertExample = new Main(); String token = insertExample.authenticate(); System.out.println("Obtained authorization token: " + token); insertExample.postItem(token); }
/** * Inserts <code>DATA_ITEM</code> by making a POST request to * <code>ITEMS_URL<code>. * @param token authentication token obtained using <code>authenticate</code> * @throws IOException if an I/O exception occurs while creating/ writing/ * reading the request */ public void postItem(String token) throws IOException { HttpURLConnection connection = (HttpURLConnection)(new URL(ITEMS_FEED)).openConnection();
connection.setDoInput(true); connection.setDoOutput(true);
// Set the properties of the connection: the Http method, the content type // of the POST request, the authorization header and the developer key connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/atom +xml"); connection.setRequestProperty("Authorization", "GoogleLogin auth=" + token); connection.setRequestProperty("X-Google-Key", "key=" + DEVELOPER_KEY);
// Post the data item OutputStream outputStream = connection.getOutputStream(); outputStream.write(DATA_ITEM.getBytes()); outputStream.close();
// Retrieve the output int responseCode = connection.getResponseCode(); InputStream inputStream; if (responseCode == HttpURLConnection.HTTP_CREATED) { inputStream = connection.getInputStream(); } else { inputStream = connection.getErrorStream(); }
// write the output to the console System.out.println(toString(inputStream)); }
/** * Retrieves the authentication token for the provided set of credentials. * @return the authorization token that can be used to access authenticated * Google Base data API feeds */ public String authenticate() { // create the login request String postOutput = null; try { URL url = new URL(AUTHENTICATION_URL); postOutput = makeLoginRequest(url); } catch (IOException e) { System.out.println("Could not connect to authentication server: " + e.toString()); System.exit(1); }
// Parse the result of the login request. If everything went fine, the // response will look like // HTTP/1.0 200 OK // Server: GFE/1.3 // Content-Type: text/plain // SID=DQAAAGgA...7Zg8CTN // LSID=DQAAAGsA...lk8BBbG // Auth=DQAAAGgA...dk3fA5N // so all we need to do is look for "Auth" and get the token that comes after it
StringTokenizer tokenizer = new StringTokenizer(postOutput, "=\n "); String token = null;
while (tokenizer.hasMoreElements()) { if (tokenizer.nextToken().equals("Auth")) { if (tokenizer.hasMoreElements()) { token = tokenizer.nextToken(); } break; } } if (token == null) { System.out.println("Authentication error. Response from server: \n" + postOutput); System.exit(1); } return token; }
/** * Makes a HTTP POST request to the provided {@code url} given the provided * {@code parameters}. It returns the output from the POST handler as a * String object. * * @param url the URL to post the request * @return the output from the handler * @throws IOException if an I/O exception occurs while * creating/writing/reading the request */ private String makeLoginRequest(URL url) throws IOException { // Create a login request. A login request is a POST request that looks like // POST /accounts/ClientLogin HTTP/1.0 // Content-type: application/x-www-form-urlencoded // Email=john...@gmail.com&Passwd=north23AZ&service=gbase&source=Insert Example
// Open connection HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
// Set properties of the connection urlConnection.setRequestMethod("POST"); urlConnection.setDoInput(true); urlConnection.setDoOutput(true); urlConnection.setUseCaches(false); urlConnection.setRequestProperty("Content-Type", "application/x-www-form- urlencoded");
// Form the POST parameters StringBuilder content = new StringBuilder(); content.append("Email=").append(URLEncoder.encode(EMAIL, "UTF-8")); content.append("&Passwd=").append(URLEncoder.encode(PASSWORD, "UTF-8")); content.append("&source=").append(URLEncoder.encode("Google Base data API example", "UTF-8")); content.append("&service=").append(URLEncoder.encode("gbase", "UTF-8"));
OutputStream outputStream = urlConnection.getOutputStream(); outputStream.write(content.toString().getBytes("UTF-8")); outputStream.close();
// Retrieve the output int responseCode = urlConnection.getResponseCode(); InputStream inputStream; if (responseCode == HttpURLConnection.HTTP_OK) { inputStream = urlConnection.getInputStream(); } else { inputStream = urlConnection.getErrorStream(); }
return toString(inputStream); }
/** * Writes the content of the input stream to a <code>String<code>. */ private String toString(InputStream inputStream) throws IOException { String string; StringBuilder outputBuilder = new StringBuilder(); if (inputStream != null) { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); while (null != (string = reader.readLine())) { outputBuilder.append(string).append('\n'); } } return outputBuilder.toString(); }
}
I don't understand why this code not work. Please, help.
Thank you
On Jul 10, 10:49 pm, Jeff S <j....@google.com> wrote:
Hi Black Eric,
Your XML seems to successfully create the item when I run it. Is the problem that your item is not displayed in search results? If it is still not working, then the problem may be elsewhere in your code and I'd be happy to take a look if you like.
Thank you,
Jeff
On Jul 9, 3:17 am, Black Eric <alex...@gmail.com> wrote:
Hello! I have problem with displayed my items in Product Search. But in Friday it work. I post items into Google Base via GoogleBase Java API using next xml:
<?xml version='1.0'?> <entry xmlns='http://www.w3.org/2005/Atom'xmlns:g='http:// base.google.com/ns/1.0'>
...
read more »




