How to make an Instagram GET Request?

时间:2017-12-18 07:49:52

标签: java android api get instagram

Sorry to come in with so little information but i'm trying to make a project in which I pull from people's public Instagram accounts in order to view them.

I'm currently at the stage in which I've registered my application, and have gotten my access token with a public_content scope.

However, searching for Instagram's endpoints, I see many // Get the current calendar NSCalendar *calendar = [NSCalendar currentCalendar]; // Get the next occurrence for the first weekday of the current calendar NSDate *startOfNextWeek = [calendar nextDateAfterDate:[NSDate date] matchingUnit:NSCalendarUnitWeekday value:calendar.firstWeekday options:NSCalendarMatchStrictly]; // Create new date components +7 days and -1 seconds NSDateComponents *endOfNextWeekComponents = [[NSDateComponents alloc] init]; endOfNextWeekComponents.day = 7; endOfNextWeekComponents.second = -1; // Add the date components to the start date to get the end date. NSDate *endOfNextWeek = [calendar dateByAddingComponents:endOfNextWeekComponents toDate:startOfNextWeek options:NSCalendarMatchStrictly]; NSLog(@"%@ - %@", startOfNextWeek, endOfNextWeek); requests along the lines of

https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS-TOKEN

I understand that I will have to replace the GET part of the link with my own, but am entirely lost as to how to call this ACCESS-TOKEN request in Java in GET.

Any advice or points in the right direction would be much appreciated.

1 个答案:

答案 0 :(得分:0)

There are several ways to do Rest APIs. One is generic Async task but I personally find it too generalized. As an alternative, you can use Volley to do network requests from Android App.

  1. Add public boolean isFilePresent(String fileName) { String path = this.getFilesDir().getAbsolutePath() + "/" + fileName; File file = new File(path); return file.exists(); } to Volley file:
build.gradle
  1. Take dependencies { compile 'com.android.volley:volley:1.1.0' } permissions on your app.

  2. Instantiate the Volley request queue with your app android.permission.INTERNET:

context
  1. Create a request for // Instantiate the RequestQueue RequestQueue queue = Volley.newRequestQueue(this); or JsonArray:
JsonObject
  1. Add the request to volley String url = "https://api.instagram.com/v1/users/self/media/recent/?access_token=DUMMY-ACCESS-TOKEN"; JsonObjectRequest jsObjRequest = new JsonObjectRequest (Request.Method.GET, url, null, new Response.Listener() { @Override public void onResponse(JSONObject response) { // Set up operation for network callback here } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub } }); :
RequestQueue