Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #32568

Getting filenotfound exception on instagram hashtag search query

Newsgroups comp.lang.java.programmer
Date 2015-09-09 11:41 -0700
Message-ID <84fd8a39-ee73-4567-b65f-ca61f2d6773c@googlegroups.com> (permalink)
Subject Getting filenotfound exception on instagram hashtag search query
From Arnab Roy <royarnab89@gmail.com>

Show all headers | View raw


I am trying to run a program which search Instagram for pictures of specific hashtag. Below is my code for the program. When I am running the program, it is not showing any error, but it is returning "filenotfoundexception" from instagram. I think it is in the endpoint url, but I can't exactly figure out where I am making the mistake. Can anyone help me figuring it out? Thanks in advance

public class SearchActivity extends Activity {
public EditText edtSearch;
private final String INSTA_CONS_ID = "xxxx";
private final String INSTA_CONS_SEC_KEY = "xxxx";
public static final String APIURL = "https://api.instagram.com/v1/tags";
ListView list;
public int index;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);

Button btnInsta =(Button)findViewById(R.id.btnInsta);
edtSearch =(EditText)findViewById(R.id.edtSearch);
list = (ListView)findViewById(R.id.list);

btnInsta.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        new SearchOnInstagram().execute(edtSearch.getText().toString());
    }
});
}
class SearchOnInstagram extends AsyncTask<String, Void, Integer> {
final List<Instagram> inst = new ArrayList<Instagram>();
final int SUCCESS = 0;
final int FAILURE = SUCCESS + 1;
ProgressDialog dialog;

@Override
protected void onPreExecute() {
    super.onPreExecute();
    dialog = ProgressDialog.show(SearchActivity.this, "", getString(R.string.searchinginsta));
}

@Override
protected Integer doInBackground(String... params) {
    try {

        Query query = new Query(params[0]);
        String urlString = APIURL + "/"+ query +"/media/recent?client_id=" + INSTA_CONS_ID;
                URL url = new URL(urlString);

        InputStream inputStream = url.openConnection().getInputStream();
        String response = streamToString(inputStream);
        JSONObject jsonObject = (JSONObject) new JSONTokener(response).nextValue();
        JSONArray jsonArray = jsonObject.getJSONArray("data");

        for (int i =0; i<= jsonArray.length(); i++) {
            JSONObject mainImageJsonObject = jsonArray.getJSONObject(index).getJSONObject("images").getJSONObject("standard_resolution");
            String imageUrlString = mainImageJsonObject.getString("url");
            String userName = "@Arnab";

            Instagram instItem = new Instagram(userName,imageUrlString);
            inst.add(instItem);
        }
        return SUCCESS;
    } 
    catch (Exception e) {
        e.printStackTrace();
    }

    return FAILURE;
}

@Override
protected void onPostExecute(Integer result) 
{
    super.onPostExecute(result);
    dialog.dismiss();
    if (result == SUCCESS) {
        list.setAdapter(new InstagramAdapter(SearchActivity.this, inst));
    } 
    else 
    {
        Toast.makeText(SearchActivity.this, getString(R.string.error), Toast.LENGTH_LONG).show();
    }
}
public static String streamToString(InputStream p_is)
{
    try
    {
        BufferedReader m_br;
        StringBuffer m_outString = new StringBuffer();
        m_br = new BufferedReader(new InputStreamReader(p_is));
        String m_read = m_br.readLine();
        while(m_read != null)
        {
            m_outString.append(m_read);
            m_read =m_br.readLine();
        }
        return m_outString.toString();
    }
    catch (Exception p_ex)
    {
        p_ex.printStackTrace();
        return "";
    }
 }



I am getting the following exception


09-09 16:20:10.070  25571-25625/com.example.smarthelp W/System.err﹕       java.io.FileNotFoundException:  https://api.instagram.com/v1/tags/Query{query='india', lang='null', locale='null', maxId=-1, count=-1, since='null', sinceId=-1, geocode='null', until='null', resultType='null', nextPageQuery='null'}/media/recent?client_id=xxx
 09-09 16:20:10.070  25571-25625/com.example.smarthelp W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:197)
 09-09 16:20:10.070  25571-25625/com.example.smarthelp W/System.err﹕ at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Getting filenotfound exception on instagram hashtag search query Arnab Roy <royarnab89@gmail.com> - 2015-09-09 11:41 -0700
  Re: Getting filenotfound exception on instagram hashtag search query Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-09-09 16:11 -0400

csiph-web