android - How to get media id of an instagram post? -


since instagram not allow post photo using api end points, i'm sharing photo on instagram app using android intent app. how media id of shared post?

can use hidden hashtags identify particular post?

if want media id shareable link, can go link. response json.

http://api.instagram.com/oembed?url=https://instagram.com/p/6ggfe9jkzm/

response:

{ "provider_url": "https://instagram.com/", "media_id": "1046665049816739046_489992346", "author_name": "8crap", "height": null, "provider_name": "instagram", "title": "just goal in life work least , paid most. #8crap", "html": "<blockquote class=\"instagram-media\" data-instgrm-captioned data-instgrm-version=\"4\" style=\" background:#fff; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:658px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);\"><div style=\"padding:8px;\"> <div style=\" background:#f8f8f8; line-height:0; margin-top:40px; padding:50% 0; text-align:center; width:100%;\"> <div style=\" background:url(data:image/png;base64,ivborw0kggoaaaansuheugaaacwaaaascamaaaapwqozaaaagfbmveuiiii9pt0ehh4gib4hibkchbwchbwchbydr+jqaaaachrstlmaba4yhyqsm5jtamwaaadfsurbvdjl7zvbegmhcaqbaf//42xcnbpaqakcm0ftumfaaibe81iqbjds3ls6zs3bipb9wed3yyxfpmhrft8sgyrcp1x8ueuxlmznwelfoycv6mhwwwmzdpekhlhlw7nwjqkhc4uizphavdza2jpzudsbzzinae2s6owh8xpmx8g7zzgkeopuoyhvgz1tbcxmkd3kwnvbu0gkhkx+izilf77iofhry1nyfnb/lqpb79drwoyjva/davg9b/rlb4cc+nqgdz/tvbbbnr6gbreqn/nrmdgaqeej7whonozjf+y2i/fzou/qaaaaaelftksuqmcc); display:block; height:44px; margin:0 auto -44px; position:relative; top:-22px; width:44px;\"></div></div> <p style=\" margin:8px 0 0 0; padding:0 4px;\"> <a href=\"https://instagram.com/p/6ggfe9jkzm/\" style=\" color:#000; font-family:arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none; word-wrap:break-word;\" target=\"_top\">just goal in life work least , paid most. #8crap</a></p> <p style=\" color:#c9c8cd; font-family:arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;\">8crap (@8crap) tarafından paylaşılan bir fotoğraf (<time style=\" font-family:arial,sans-serif; font-size:14px; line-height:17px;\" datetime=\"2015-08-08t00:03:38+00:00\">7 ağu 2015, 17:03 pdt</time>)</p></div></blockquote>\n<script async defer src=\"//platform.instagram.com/en_us/embeds.js\"></script>", "width": 658, "version": "1.0", "author_url": "https://instagram.com/8crap", "author_id": 489992346, "type": "rich" } 

so, media_id item.

code connection , parsing json:

    // these 2 need declared outside try/catch     // can closed in block.     httpurlconnection urlconnection = null;     bufferedreader reader = null;      // contain raw json response string.     string jsonstr = null;      try {         // construct url.  "based_url + urlstring" should          // "http://api.instagram.com/oembed?url=https://instagram.com/p/6ggfe9jkzm/"         url url = new url(based_url + urlstring);          // open connection         urlconnection = (httpurlconnection) url.openconnection();         urlconnection.connect();          // read input stream string         inputstream inputstream = urlconnection.getinputstream();         stringbuffer buffer = new stringbuffer();         if (inputstream == null) {             // nothing do.             return null;         }         reader = new bufferedreader(new inputstreamreader(inputstream));          string line;         while ((line = reader.readline()) != null) {             // since it's json, adding newline isn't necessary (it won't affect parsing)             // make debugging *lot* easier if print out completed             // buffer debugging.             buffer.append(line + "\n");         }          if (buffer.length() == 0) {             // stream empty.  no point in parsing.             return null;         }         jsonstr = buffer.tostring();     } catch (ioexception e) {         exception = e;         // if code didn't weather data, there's no point in attemping         // parse it.         return null;     } finally{         if (urlconnection != null) {             urlconnection.disconnect();         }         if (reader != null) {             try {                 reader.close();             } catch (final ioexception e) {                 exception = e;             }         }     }       try {         string mediaid = getmediaidfromjson(jsonstr);     } catch (jsonexception e) {         exception = e;     }    private string getmediaidfromjson(string jsonstr) throws jsonexception {     // parse media id json     if (jsonstr == null) {         return "";     }      final string media_id = "media_id";     jsonobject jsonobject = new jsonobject(jsonstr);     string mediaid = jsonobject.getstring(media_id);      return mediaid; } 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -