机器人:如何获取用户的照片Instagram的? [英] android: how to get user photos in Instagram?

查看:170
本文介绍了机器人:如何获取用户的照片Instagram的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我的要求是获取用户的照片,并显示在我的应用程序。

有关,我验证,得到了访问令牌,然后输入用户名密码,而是说明你没有权限打开这个页面。接下来,我怎么能得到用户的个人资料和照片。

我在这里的code是:

 字符串URL =htt​​ps://instagram.com/oauth/authorize? +RESPONSE_TYPE =记号+
 &放大器; redirect_uri =+ CALLBACK_URL +&放大器;范围=基本的+&放大器; CLIENT_ID =+ CLIENT_ID;

  的WebView的WebView =(web视图)findViewById(R.id.webview);

  webview.setWebViewClient(新WebViewClient(){

        公共无效onPageStarted(web视图查看,字符串URL,位图图标){
            字符串片段=#access_token =;
            INT开始= url.indexOf(片段);
            如果(开始> -1){

                //你可以使用accessToken的API调用了。
                串accessToken = url.substring(开始+ fragment.length(),url.length());

                Log.v(TAG,OAuth的完整,令牌:[+ accessToken +。);
                Log.i(TAG,+ accessToken);
Toast.makeText(ActivityWebView.this,令牌+ accessToken,Toast.LENGTH_SHORT).show();
            }
        }
    });

    webview.loadUrl(URL);
}
 

解决方案

试试这个codeI得到的解决方案,从这样的:

  URL例如=新的URL(https://api.instagram.com/v1/users/self/media/recent?access_token=
                            + accessToken);

            的URLConnection TC = example.openConnection();
            的BufferedReader在=新的BufferedReader(新的InputStreamReader(
                    tc.getInputStream()));

            串线;
            而((行= in.readLine())!= NULL){
                JSONObject的OB =新的JSONObject(线);

                JSONArray对象= ob.getJSONArray(数据);

                的for(int i = 0; I< object.length();我++){


                    的JSONObject祚=(的JSONObject)object.get(我);
                    JSONObject的NJA =(的JSONObject)jo.getJSONObject(照片);

                    JSONObject的purl3 =(的JSONObject)NJA
                            .getJSONObject(缩略图);
                    Log.i(TAG,+ purl3.getString(URL));
                }

            }
        }赶上(MalformedURLException异常E){

            e.printStackTrace();
        }赶上(IOException异常E){

            e.printStackTrace();
        }赶上(JSONException E){

            e.printStackTrace();
        }

    }
 

In my app my requirement is to get the user photos and show in my app.

For that i am authenticate , got access token and enter username password but that shows you don't have permission to open this page. next how can i get user profile and photos.

here my code is:

 String url ="https://instagram.com/oauth/authorize?" +"response_type=token" + 
 "&redirect_uri=" + CALLBACK_URL+"&scope=basic"+"&client_id=" + CLIENT_ID ;

  WebView webview = (WebView)findViewById(R.id.webview);

  webview.setWebViewClient(new WebViewClient() {

        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            String fragment = "#access_token=";
            int start = url.indexOf(fragment);
            if (start > -1) {

                // You can use the accessToken for api calls now.
                String accessToken = url.substring(start + fragment.length(), url.length());

                Log.v(TAG, "OAuth complete, token: [" + accessToken + "].");
                Log.i(TAG, "" +accessToken);
Toast.makeText(ActivityWebView.this, "Token: " + accessToken, Toast.LENGTH_SHORT).show();
            }
        }
    });

    webview.loadUrl(url);
}

解决方案

try this code i got solution from this:

 URL example = new URL("https://api.instagram.com/v1/users/self/media/recent?access_token="
                            + accessToken);

            URLConnection tc = example.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    tc.getInputStream()));

            String line;
            while ((line = in.readLine()) != null) {
                JSONObject ob = new JSONObject(line);

                JSONArray object = ob.getJSONArray("data");

                for (int i = 0; i < object.length(); i++) {


                    JSONObject jo = (JSONObject) object.get(i);
                    JSONObject nja = (JSONObject) jo.getJSONObject(photos);

                    JSONObject purl3 = (JSONObject) nja
                            .getJSONObject("thumbnail");
                    Log.i(TAG, "" + purl3.getString("url"));
                }

            }
        } catch (MalformedURLException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();
        } catch (JSONException e) {

            e.printStackTrace();
        }

    }

这篇关于机器人:如何获取用户的照片Instagram的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆