Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32568 > unrolled thread
| Started by | Arnab Roy <royarnab89@gmail.com> |
|---|---|
| First post | 2015-09-09 11:41 -0700 |
| Last post | 2015-09-09 16:11 -0400 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | Arnab Roy <royarnab89@gmail.com> |
|---|---|
| Date | 2015-09-09 11:41 -0700 |
| Subject | Getting filenotfound exception on instagram hashtag search query |
| Message-ID | <84fd8a39-ee73-4567-b65f-ca61f2d6773c@googlegroups.com> |
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)
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-09-09 16:11 -0400 |
| Message-ID | <msq3lm$qpc$1@dont-email.me> |
| In reply to | #32568 |
On 9/9/2015 2:41 PM, Arnab Roy wrote:
> 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
I'm not familiar with Instagram nor with the API's you are
using to access it, but the error message seems clear enough. Does
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
... look like a syntactically valid URL to you?
I suspect the problem is caused by
> Query query = new Query(params[0]);
> String urlString = APIURL + "/"+ query +"/media/recent?client_id=" + INSTA_CONS_ID;
> URL url = new URL(urlString);
... where query.toString() is most likely producing all that junk
in the middle of your URL. You probably want some other method of
query -- but, being unfamiliar with Query (it's probably not the
javax.management.Query class, but some "foreign import"), I don't
know what to suggest.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web