0
j.setUrl("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AIzaSyA712jyN6NY0VXSGf8zgXfXSRhq01O8RLY");

This is my json url with my key. It always gives me status request denied . I have tried making alot of keys with debug keystore and new keystores but nothing works . it is the example url of google. It doesn't work for me. If you want to provide a solution regarding a new key please give me the detailed procedure on how to get a valid debug key. Please be very detailed. If you want to provide a solution regarding sensor paramater its there already. If you want json parser file its as below

    package com.json;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.AsyncTask;
public class JSONParser extends AsyncTask<Void, Void, JSONObject> {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";
    private String url;

    // constructor
    public JSONParser() {

    }

@Override
protected JSONObject doInBackground(Void... params) {
    // defaultHttpClient
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(getUrl());

    HttpResponse httpResponse = null;
    try {
        httpResponse = httpClient.execute(httpPost);
    } catch (ClientProtocolException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    HttpEntity httpEntity = httpResponse.getEntity();
    try {
        is = httpEntity.getContent();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    BufferedReader reader = null;
    try {
        reader = new BufferedReader(
                new InputStreamReader(is, "iso-8859-1"), 8);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    StringBuilder sb = new StringBuilder();
    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    try {
        is.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    json = sb.toString();

    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // return JSON String
    return jObj;
}

public String getUrl() {
    return url;
}

public void setUrl(String url) {
    this.url = url;
}

}


EDIT : I looked at the reports of my api console it shows that requests were made, since i see requests I presume that the key is NOT invalid as it correctly leads to my api console. Please correct me if I'm wrong?


EDIT 2 : So I tried everything now made a new Id, got a new api key for my debug keystore, made a whole new project using the url and json parser class. I still get request denied. Can someone help me?

That1Guy
  • 7,075
  • 4
  • 47
  • 59
  • in ur url try to replace nearbysearch with search its work for me and use this link to get debug key http://stackoverflow.com/questions/5262695/how-to-get-md5-from-debug-keystore-file – steevoo Apr 03 '13 at 10:05
  • Doesn't work still the same i still get request denied – Karan Jhanjee Apr 03 '13 at 10:09
  • I have done that got the sha1 certificate and then the key but even after doing that 5 times I still get this error – Karan Jhanjee Apr 03 '13 at 10:10
  • the key u r using is not valid – steevoo Apr 03 '13 at 10:14
  • I have followed the following procedure to get the key :- 1.)Get the sha1 certificate for debug.keystore file 2.)goto to apis console and click create a new android key 3.)enter the sha1 certificate, add ';' to it and then add the package name which in my case is com.json 4.)get the new key ,copy it and use it in the url. what am i missing , what else is left? – Karan Jhanjee Apr 03 '13 at 10:21
  • to know if key valid check the url on browser will give json result – steevoo Apr 03 '13 at 10:21
  • it gave me request denied , now how to get a valid key, is my procedure wrong and if it is wrong, please tell me how cause the 1st answer and my procedure are the same. – Karan Jhanjee Apr 03 '13 at 10:29
  • generated a new key still getting request denied – Karan Jhanjee Apr 03 '13 at 10:46

2 Answers2

1

1)How to create KeyStore

Project >> Export >> ExportAndroidApplication >> Next >> Create New Keystore (Remember Keystore Path) >> Fill All Detail >> ...etc

Now your keystore and Apk is created.

2)How to get Certificate fingerprint (MD5)

$ keytool -list -alias alias_name -keystore my-release-key.keystore

for more detail go here

Now you got fingerprint like as

Certificate fingerprint (MD5): 94:1E:43:49:87:73:BB:E6:A6:88:D7:20:F1:8E:B5:98

3)How to get MapApiKey click here and paste your MD5 then u will get MapAPIKey. Use this key in your application.

steevoo
  • 621
  • 6
  • 18
  • Sorry sir but this is the old method which was used with maps api v1. Now woth maps apiv2, v3 and places api we use the sha1 certificate and get the key from api console – Karan Jhanjee Apr 03 '13 at 11:15
1

It finally works so what I did was

  • Delete my old api project from api console.
  • Created a new project.
  • Started only the google places api service.
  • Clicked the try it out link
  • My browser gave me the right results using the default key it had made.
  • Copied the key from the url field.
  • Used it in my app. IT WORKS. HURRAH! :) I did not create a new android key.