Invalid API key -- need help


#1

Hi friends,
On running the Photo gallery app am getting an INVALID API KEY Exception

What to do…??


02-13 11:39:19.065: I/FlickerFetchr(1836): Recieved xml<?xml version="1.0" encoding="utf-8" ?>
02-13 11:39:19.065: I/FlickerFetchr(1836): <rsp stat="fail">
02-13 11:39:19.065: I/FlickerFetchr(1836): 	<err code="100" msg="Invalid API Key (Key has invalid format)" />
02-13 11:39:19.065: I/FlickerFetchr(1836): </rsp>

this is the code

package com.spoors.photogallery;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.net.Uri;
import android.util.Log;

public class FlickerFetchr{
	public static final String TAG = "FlickerFetchr";

	private static final String ENDPOINT = "http://api.flickr.com/services/rest/"; 
	private static final String API_KEY ="4b53a08d5aa9e53060c00b9436ba3364"; 
	private static final String METHOD_GET_RECENT = "flickr.photos.getRecent";
	private static final String PARAM_EXTRAS = "extras";
	private static final String EXTRA_SMALL_URL = "url_s";

	private static final String XML_PHOTO = "photo";


	byte[]   getUrlBytes(String urlSpec) throws IOException
	{
		URL url = new URL(urlSpec);
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		try
		{
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			InputStream in = connection.getInputStream();
			if(connection.getResponseCode() != HttpURLConnection.HTTP_OK)
				return null;
			int bytesRead = 0;
			byte[] buffer = new byte[1024];
			while((bytesRead = in.read(buffer)) >0)
				out.write(buffer,0,bytesRead);
			out.close();
			return out.toByteArray();
		}
		finally
		{
			connection.disconnect();
		}
	}
	public String getUrl(String urlSpec) throws IOException {
		return new String(getUrlBytes(urlSpec));
	}
	public void fetchItems() {
		try
		{
			String url = Uri.parse(ENDPOINT).buildUpon()
					.appendQueryParameter("method",METHOD_GET_RECENT)
					.appendQueryParameter("apikey",API_KEY)
					.appendQueryParameter(PARAM_EXTRAS,EXTRA_SMALL_URL)
					.build().toString();

			String xmlString = getUrl(url);

			Log.i(TAG, "Recieved xml" + xmlString);

		}
		catch(IOException e)
		{
			Log.e(TAG,"failed to fetch items" ,e);
		}
	}

	void parseItems(ArrayList<GalleryItem> items,XmlPullParser parser) 
			throws IOException,XmlPullParserException
	{
	int eventType = parser.next();
	while(eventType != XmlPullParser.END_DOCUMENT)
	{
		if(eventType == XmlPullParser.START_TAG && XML_PHOTO.equals(parser.getName()))
		{
			String id = parser.getAttributeValue(null,"id");
			String caption = parser.getAttributeValue(null,"title");
			String smallUrl = parser.getAttributeValue(null, EXTRA_SMALL_URL);

			GalleryItem galleryItem = new GalleryItem();
			galleryItem.setId(id);
			galleryItem.setCaption(caption);
			galleryItem.setUrl(smallUrl);
			items.add(galleryItem);

		}

		eventType = parser.next();
	}
	}

}

#2

It maybe because you missed the “_”

change it

to