gpt4 book ai didi

android:如何在Instagram中获取用户照片?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:46:56 26 4
gpt4 key购买 nike

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

为此,我进行了身份验证,获得了访问 token 并输入了用户名密码,但这表明您无权打开此页面。接下来如何获取用户个人资料和照片。

我的代码是:

 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);
}

最佳答案

试试这段代码,我从中得到了解决方案:

 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();
}

}

关于android:如何在Instagram中获取用户照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12505956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com