├── .gitignore
├── README.md
├── android-instagram-oauth-example
├── AndroidManifest.xml
├── default.properties
├── res
│ ├── drawable
│ │ └── icon.png
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── br
│ └── com
│ └── dina
│ └── oauth
│ └── instagram
│ └── example
│ ├── ApplicationData.java
│ └── MainActivity.java
└── android-instagram-oauth
├── AndroidManifest.xml
├── default.properties
├── res
├── drawable
│ └── icon.png
├── layout
│ └── main.xml
└── values
│ └── strings.xml
└── src
└── br
└── com
└── dina
└── oauth
└── instagram
├── InstagramApp.java
├── InstagramDialog.java
├── InstagramSession.java
└── Main.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .project
3 | .settings
4 | bin
5 | gen
6 | target
7 |
8 | local.properties
9 | build.xml
10 | proguard.cfg
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android OAuth Library for Instagram Applications
2 | ---------------
3 |
4 | 
5 | 
6 | 
7 |
8 | ## Usage
9 |
10 | You can create an utility class where you can define your application credentials, like the one below:
11 |
12 | public class ApplicationData {
13 | public static final String CLIENT_ID = "";
14 | public static final String CLIENT_SECRET = "";
15 | public static final String CALLBACK_URL = "";
16 | }
17 |
18 | To instantiage the main class for the oauth flow, you need to follow the code below:
19 |
20 | InstagramApp mApp; = new InstagramApp(this,
21 | ApplicationData.CLIENT_ID,
22 | ApplicationData.CLIENT_SECRET,
23 | ApplicationData.CALLBACK_URL);
24 |
25 | Once you have the main class ready for the authorization, you can start the authorization flow by calling the following method:
26 |
27 | mApp.authorize();
28 |
29 | If you token is expired, you can call this method to refresh it:
30 |
31 | mApp.refreshToken();
32 |
33 | To get the account list, call the following method
34 |
35 | mApp.getAccountList();
36 |
37 | ## Contributions
38 |
39 | Any contribution to this project is welcome, feel free to fork and create pull requests
40 |
41 | ## Other Android Libraries
42 |
43 | Use these libraries also to get the best for your android application
44 |
45 | * [Android ActionBar](https://github.com/johannilsson/android-actionbar) by [Johan Nilsson](https://github.com/johannilsson)
46 | * [Android Pull to Refresh](https://github.com/johannilsson/android-pulltorefresh) by [Johan Nilsson](https://github.com/johannilsson)
47 | * [SwipeView](https://github.com/fry15/uk.co.jasonfry.android.tools) by [Jason Fry](https://github.com/fry15)
48 | * [Facebook Integration](https://github.com/lorensiuswlt/AndroidFacebook) by [Lorensius](https://github.com/lorensiuswlt)
49 | * [Twitter Integration](https://github.com/lorensiuswlt/AndroidTwitter) by [Lorensius](https://github.com/lorensiuswlt)
50 | * [Quick Actions](https://github.com/lorensiuswlt/NewQuickAction) by [Lorensius](https://github.com/lorensiuswlt)
--------------------------------------------------------------------------------
/android-instagram-oauth-example/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/android-instagram-oauth-example/default.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-7
12 | android.library.reference.1=../android-instagram-oauth
13 |
--------------------------------------------------------------------------------
/android-instagram-oauth-example/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thiagolocatelli/android-instagram-oauth/fc9a698f263b3014fee2dcce1e86df005f5d52d9/android-instagram-oauth-example/res/drawable/icon.png
--------------------------------------------------------------------------------
/android-instagram-oauth-example/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/android-instagram-oauth-example/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Instagram OAuth
4 |
5 |
--------------------------------------------------------------------------------
/android-instagram-oauth-example/src/br/com/dina/oauth/instagram/example/ApplicationData.java:
--------------------------------------------------------------------------------
1 | package br.com.dina.oauth.instagram.example;
2 |
3 | public class ApplicationData {
4 | public static final String CLIENT_ID = "379d744556c743c090c8a2014779f59f";
5 | public static final String CLIENT_SECRET = "fd6ec75e44054da1a5088ad2d72f2253";
6 | public static final String CALLBACK_URL = "instagram://connect";
7 | }
8 |
--------------------------------------------------------------------------------
/android-instagram-oauth-example/src/br/com/dina/oauth/instagram/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package br.com.dina.oauth.instagram.example;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.content.DialogInterface;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 | import android.widget.Button;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 | import br.com.dina.oauth.instagram.InstagramApp;
13 | import br.com.dina.oauth.instagram.InstagramApp.OAuthAuthenticationListener;
14 |
15 | public class MainActivity extends Activity {
16 |
17 | private InstagramApp mApp;
18 | private Button btnConnect;
19 | private TextView tvSummary;
20 |
21 | @Override
22 | public void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.main);
25 |
26 | mApp = new InstagramApp(this, ApplicationData.CLIENT_ID,
27 | ApplicationData.CLIENT_SECRET, ApplicationData.CALLBACK_URL);
28 | mApp.setListener(listener);
29 |
30 | tvSummary = (TextView) findViewById(R.id.tvSummary);
31 |
32 | btnConnect = (Button) findViewById(R.id.btnConnect);
33 | btnConnect.setOnClickListener(new OnClickListener() {
34 |
35 | @Override
36 | public void onClick(View view) {
37 | if (mApp.hasAccessToken()) {
38 | final AlertDialog.Builder builder = new AlertDialog.Builder(
39 | MainActivity.this);
40 | builder.setMessage("Disconnect from Instagram?")
41 | .setCancelable(false)
42 | .setPositiveButton("Yes",
43 | new DialogInterface.OnClickListener() {
44 | public void onClick(
45 | DialogInterface dialog, int id) {
46 | mApp.resetAccessToken();
47 | btnConnect.setText("Connect");
48 | tvSummary.setText("Not connected");
49 | }
50 | })
51 | .setNegativeButton("No",
52 | new DialogInterface.OnClickListener() {
53 | public void onClick(
54 | DialogInterface dialog, int id) {
55 | dialog.cancel();
56 | }
57 | });
58 | final AlertDialog alert = builder.create();
59 | alert.show();
60 | } else {
61 | mApp.authorize();
62 | }
63 | }
64 | });
65 |
66 | if (mApp.hasAccessToken()) {
67 | tvSummary.setText("Connected as " + mApp.getUserName());
68 | btnConnect.setText("Disconnect");
69 | }
70 |
71 | }
72 |
73 | OAuthAuthenticationListener listener = new OAuthAuthenticationListener() {
74 |
75 | @Override
76 | public void onSuccess() {
77 | tvSummary.setText("Connected as " + mApp.getUserName());
78 | btnConnect.setText("Disconnect");
79 | }
80 |
81 | @Override
82 | public void onFail(String error) {
83 | Toast.makeText(MainActivity.this, error, Toast.LENGTH_SHORT).show();
84 | }
85 | };
86 | }
--------------------------------------------------------------------------------
/android-instagram-oauth/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/android-instagram-oauth/default.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-7
12 | android.library=true
13 |
--------------------------------------------------------------------------------
/android-instagram-oauth/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thiagolocatelli/android-instagram-oauth/fc9a698f263b3014fee2dcce1e86df005f5d52d9/android-instagram-oauth/res/drawable/icon.png
--------------------------------------------------------------------------------
/android-instagram-oauth/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/android-instagram-oauth/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | android-instagram-oauth
4 |
5 |
--------------------------------------------------------------------------------
/android-instagram-oauth/src/br/com/dina/oauth/instagram/InstagramApp.java:
--------------------------------------------------------------------------------
1 | package br.com.dina.oauth.instagram;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 | import java.io.OutputStreamWriter;
8 | import java.net.HttpURLConnection;
9 | import java.net.URL;
10 |
11 | import org.json.JSONObject;
12 | import org.json.JSONTokener;
13 |
14 | import android.app.ProgressDialog;
15 | import android.content.Context;
16 | import android.content.Intent;
17 | import android.net.Uri;
18 | import android.os.Handler;
19 | import android.os.Message;
20 | import android.util.Log;
21 | import br.com.dina.oauth.instagram.InstagramDialog.OAuthDialogListener;
22 |
23 | /**
24 | *
25 | * @author Thiago Locatelli
26 | * @author Lorensius W. L T
27 | *
28 | */
29 | public class InstagramApp {
30 |
31 | private InstagramSession mSession;
32 | private InstagramDialog mDialog;
33 | private OAuthAuthenticationListener mListener;
34 | private ProgressDialog mProgress;
35 | private String mAuthUrl;
36 | private String mTokenUrl;
37 | private String mAccessToken;
38 | private Context mCtx;
39 |
40 | private String mClientId;
41 | private String mClientSecret;
42 |
43 |
44 | private static int WHAT_FINALIZE = 0;
45 | private static int WHAT_ERROR = 1;
46 | private static int WHAT_FETCH_INFO = 2;
47 |
48 | /**
49 | * Callback url, as set in 'Manage OAuth Costumers' page
50 | * (https://developer.github.com/)
51 | */
52 |
53 | public static String mCallbackUrl = "";
54 | private static final String AUTH_URL = "https://api.instagram.com/oauth/authorize/";
55 | private static final String TOKEN_URL = "https://api.instagram.com/oauth/access_token";
56 | private static final String API_URL = "https://api.instagram.com/v1";
57 |
58 | private static final String TAG = "InstagramAPI";
59 |
60 | public InstagramApp(Context context, String clientId, String clientSecret,
61 | String callbackUrl) {
62 |
63 | mClientId = clientId;
64 | mClientSecret = clientSecret;
65 | mCtx = context;
66 | mSession = new InstagramSession(context);
67 | mAccessToken = mSession.getAccessToken();
68 | mCallbackUrl = callbackUrl;
69 | mTokenUrl = TOKEN_URL + "?client_id=" + clientId + "&client_secret="
70 | + clientSecret + "&redirect_uri=" + mCallbackUrl + "&grant_type=authorization_code";
71 | mAuthUrl = AUTH_URL + "?client_id=" + clientId + "&redirect_uri="
72 | + mCallbackUrl + "&response_type=code&display=touch&scope=likes+comments+relationships";
73 |
74 | OAuthDialogListener listener = new OAuthDialogListener() {
75 | @Override
76 | public void onComplete(String code) {
77 | getAccessToken(code);
78 | }
79 |
80 | @Override
81 | public void onError(String error) {
82 | mListener.onFail("Authorization failed");
83 | }
84 | };
85 |
86 | mDialog = new InstagramDialog(context, mAuthUrl, listener);
87 | mProgress = new ProgressDialog(context);
88 | mProgress.setCancelable(false);
89 | }
90 |
91 | private void getAccessToken(final String code) {
92 | mProgress.setMessage("Getting access token ...");
93 | mProgress.show();
94 |
95 | new Thread() {
96 | @Override
97 | public void run() {
98 | Log.i(TAG, "Getting access token");
99 | int what = WHAT_FETCH_INFO;
100 | try {
101 | URL url = new URL(TOKEN_URL);
102 | //URL url = new URL(mTokenUrl + "&code=" + code);
103 | Log.i(TAG, "Opening Token URL " + url.toString());
104 | HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
105 | urlConnection.setRequestMethod("POST");
106 | urlConnection.setDoInput(true);
107 | urlConnection.setDoOutput(true);
108 | //urlConnection.connect();
109 | OutputStreamWriter writer = new OutputStreamWriter(urlConnection.getOutputStream());
110 | writer.write("client_id="+mClientId+
111 | "&client_secret="+mClientSecret+
112 | "&grant_type=authorization_code" +
113 | "&redirect_uri="+mCallbackUrl+
114 | "&code=" + code);
115 | writer.flush();
116 | String response = streamToString(urlConnection.getInputStream());
117 | Log.i(TAG, "response " + response);
118 | JSONObject jsonObj = (JSONObject) new JSONTokener(response).nextValue();
119 |
120 | mAccessToken = jsonObj.getString("access_token");
121 | Log.i(TAG, "Got access token: " + mAccessToken);
122 |
123 | String id = jsonObj.getJSONObject("user").getString("id");
124 | String user = jsonObj.getJSONObject("user").getString("username");
125 | String name = jsonObj.getJSONObject("user").getString("full_name");
126 |
127 | mSession.storeAccessToken(mAccessToken, id, user, name);
128 |
129 | } catch (Exception ex) {
130 | what = WHAT_ERROR;
131 | ex.printStackTrace();
132 | }
133 |
134 | mHandler.sendMessage(mHandler.obtainMessage(what, 1, 0));
135 | }
136 | }.start();
137 | }
138 |
139 | private void fetchUserName() {
140 | mProgress.setMessage("Finalizing ...");
141 |
142 | new Thread() {
143 | @Override
144 | public void run() {
145 | Log.i(TAG, "Fetching user info");
146 | int what = WHAT_FINALIZE;
147 | try {
148 | URL url = new URL(API_URL + "/users/" + mSession.getId() + "/?access_token=" + mAccessToken);
149 |
150 | Log.d(TAG, "Opening URL " + url.toString());
151 | HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
152 | urlConnection.setRequestMethod("GET");
153 | urlConnection.setDoInput(true);
154 | urlConnection.connect();
155 | String response = streamToString(urlConnection.getInputStream());
156 | System.out.println(response);
157 | JSONObject jsonObj = (JSONObject) new JSONTokener(response).nextValue();
158 | String name = jsonObj.getJSONObject("data").getString("full_name");
159 | String bio = jsonObj.getJSONObject("data").getString("bio");
160 | Log.i(TAG, "Got name: " + name + ", bio [" + bio + "]");
161 | } catch (Exception ex) {
162 | what = WHAT_ERROR;
163 | ex.printStackTrace();
164 | }
165 |
166 | mHandler.sendMessage(mHandler.obtainMessage(what, 2, 0));
167 | }
168 | }.start();
169 |
170 | }
171 |
172 |
173 | private Handler mHandler = new Handler() {
174 | @Override
175 | public void handleMessage(Message msg) {
176 | if (msg.what == WHAT_ERROR) {
177 | mProgress.dismiss();
178 | if(msg.arg1 == 1) {
179 | mListener.onFail("Failed to get access token");
180 | }
181 | else if(msg.arg1 == 2) {
182 | mListener.onFail("Failed to get user information");
183 | }
184 | }
185 | else if(msg.what == WHAT_FETCH_INFO) {
186 | fetchUserName();
187 | }
188 | else {
189 | mProgress.dismiss();
190 | mListener.onSuccess();
191 | }
192 | }
193 | };
194 |
195 | public boolean hasAccessToken() {
196 | return (mAccessToken == null) ? false : true;
197 | }
198 |
199 | public void setListener(OAuthAuthenticationListener listener) {
200 | mListener = listener;
201 | }
202 |
203 | public String getUserName() {
204 | return mSession.getUsername();
205 | }
206 |
207 | public String getId() {
208 | return mSession.getId();
209 | }
210 |
211 | public String getName() {
212 | return mSession.getName();
213 | }
214 |
215 | public void authorize() {
216 | //Intent webAuthIntent = new Intent(Intent.ACTION_VIEW);
217 | //webAuthIntent.setData(Uri.parse(AUTH_URL));
218 | //mCtx.startActivity(webAuthIntent);
219 | mDialog.show();
220 | }
221 |
222 | private String streamToString(InputStream is) throws IOException {
223 | String str = "";
224 |
225 | if (is != null) {
226 | StringBuilder sb = new StringBuilder();
227 | String line;
228 |
229 | try {
230 | BufferedReader reader = new BufferedReader(
231 | new InputStreamReader(is));
232 |
233 | while ((line = reader.readLine()) != null) {
234 | sb.append(line);
235 | }
236 |
237 | reader.close();
238 | } finally {
239 | is.close();
240 | }
241 |
242 | str = sb.toString();
243 | }
244 |
245 | return str;
246 | }
247 |
248 | public void resetAccessToken() {
249 | if (mAccessToken != null) {
250 | mSession.resetAccessToken();
251 | mAccessToken = null;
252 | }
253 | }
254 |
255 | public interface OAuthAuthenticationListener {
256 | public abstract void onSuccess();
257 |
258 | public abstract void onFail(String error);
259 | }
260 | }
--------------------------------------------------------------------------------
/android-instagram-oauth/src/br/com/dina/oauth/instagram/InstagramDialog.java:
--------------------------------------------------------------------------------
1 | package br.com.dina.oauth.instagram;
2 |
3 | import android.app.Dialog;
4 | import android.app.ProgressDialog;
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.Color;
8 | import android.graphics.Typeface;
9 | import android.os.Bundle;
10 | import android.util.Log;
11 | import android.view.Display;
12 | import android.view.ViewGroup;
13 | import android.view.Window;
14 | import android.webkit.CookieManager;
15 | import android.webkit.CookieSyncManager;
16 | import android.webkit.WebView;
17 | import android.webkit.WebViewClient;
18 | import android.widget.FrameLayout;
19 | import android.widget.LinearLayout;
20 | import android.widget.TextView;
21 |
22 | /**
23 | * Display 37Signals authentication dialog.
24 | *
25 | * @author Thiago Locatelli
26 | * @author Lorensius W. L T
27 | *
28 | */
29 | public class InstagramDialog extends Dialog {
30 |
31 | static final float[] DIMENSIONS_LANDSCAPE = { 460, 260 };
32 | static final float[] DIMENSIONS_PORTRAIT = { 280, 420 };
33 | static final FrameLayout.LayoutParams FILL = new FrameLayout.LayoutParams(
34 | ViewGroup.LayoutParams.FILL_PARENT,
35 | ViewGroup.LayoutParams.FILL_PARENT);
36 | static final int MARGIN = 4;
37 | static final int PADDING = 2;
38 |
39 | private String mUrl;
40 | private OAuthDialogListener mListener;
41 | private ProgressDialog mSpinner;
42 | private WebView mWebView;
43 | private LinearLayout mContent;
44 | private TextView mTitle;
45 |
46 | private static final String TAG = "Instagram-WebView";
47 |
48 | public InstagramDialog(Context context, String url,
49 | OAuthDialogListener listener) {
50 | super(context);
51 |
52 | mUrl = url;
53 | mListener = listener;
54 | }
55 |
56 | @Override
57 | protected void onCreate(Bundle savedInstanceState) {
58 | super.onCreate(savedInstanceState);
59 |
60 | mSpinner = new ProgressDialog(getContext());
61 | mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
62 | mSpinner.setMessage("Loading...");
63 | mContent = new LinearLayout(getContext());
64 | mContent.setOrientation(LinearLayout.VERTICAL);
65 | setUpTitle();
66 | setUpWebView();
67 |
68 | Display display = getWindow().getWindowManager().getDefaultDisplay();
69 | final float scale = getContext().getResources().getDisplayMetrics().density;
70 | float[] dimensions = (display.getWidth() < display.getHeight()) ? DIMENSIONS_PORTRAIT
71 | : DIMENSIONS_LANDSCAPE;
72 |
73 | addContentView(mContent, new FrameLayout.LayoutParams(
74 | (int) (dimensions[0] * scale + 0.5f), (int) (dimensions[1]
75 | * scale + 0.5f)));
76 | CookieSyncManager.createInstance(getContext());
77 | CookieManager cookieManager = CookieManager.getInstance();
78 | cookieManager.removeAllCookie();
79 | }
80 |
81 | private void setUpTitle() {
82 | requestWindowFeature(Window.FEATURE_NO_TITLE);
83 | mTitle = new TextView(getContext());
84 | mTitle.setText("Instagram");
85 | mTitle.setTextColor(Color.WHITE);
86 | mTitle.setTypeface(Typeface.DEFAULT_BOLD);
87 | mTitle.setBackgroundColor(Color.BLACK);
88 | mTitle.setPadding(MARGIN + PADDING, MARGIN, MARGIN, MARGIN);
89 | mContent.addView(mTitle);
90 | }
91 |
92 | private void setUpWebView() {
93 | mWebView = new WebView(getContext());
94 | mWebView.setVerticalScrollBarEnabled(false);
95 | mWebView.setHorizontalScrollBarEnabled(false);
96 | mWebView.setWebViewClient(new OAuthWebViewClient());
97 | mWebView.getSettings().setJavaScriptEnabled(true);
98 | mWebView.loadUrl(mUrl);
99 | mWebView.setLayoutParams(FILL);
100 | mContent.addView(mWebView);
101 | }
102 |
103 | private class OAuthWebViewClient extends WebViewClient {
104 |
105 | @Override
106 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
107 | Log.d(TAG, "Redirecting URL " + url);
108 |
109 | if (url.startsWith(InstagramApp.mCallbackUrl)) {
110 | String urls[] = url.split("=");
111 | mListener.onComplete(urls[1]);
112 | InstagramDialog.this.dismiss();
113 | return true;
114 | }
115 | return false;
116 | }
117 |
118 | @Override
119 | public void onReceivedError(WebView view, int errorCode,
120 | String description, String failingUrl) {
121 | Log.d(TAG, "Page error: " + description);
122 |
123 | super.onReceivedError(view, errorCode, description, failingUrl);
124 | mListener.onError(description);
125 | InstagramDialog.this.dismiss();
126 | }
127 |
128 | @Override
129 | public void onPageStarted(WebView view, String url, Bitmap favicon) {
130 | Log.d(TAG, "Loading URL: " + url);
131 |
132 | super.onPageStarted(view, url, favicon);
133 | mSpinner.show();
134 | }
135 |
136 | @Override
137 | public void onPageFinished(WebView view, String url) {
138 | super.onPageFinished(view, url);
139 | String title = mWebView.getTitle();
140 | if (title != null && title.length() > 0) {
141 | mTitle.setText(title);
142 | }
143 | Log.d(TAG, "onPageFinished URL: " + url);
144 | mSpinner.dismiss();
145 | }
146 |
147 | }
148 |
149 | public interface OAuthDialogListener {
150 | public abstract void onComplete(String accessToken);
151 | public abstract void onError(String error);
152 | }
153 |
154 | }
--------------------------------------------------------------------------------
/android-instagram-oauth/src/br/com/dina/oauth/instagram/InstagramSession.java:
--------------------------------------------------------------------------------
1 | package br.com.dina.oauth.instagram;
2 |
3 | import android.content.SharedPreferences;
4 | import android.content.SharedPreferences.Editor;
5 | import android.content.Context;
6 |
7 | /**
8 | * Manage access token and user name. Uses shared preferences to store access
9 | * token and user name.
10 | *
11 | * @author Thiago Locatelli
12 | * @author Lorensius W. L T
13 | *
14 | */
15 | public class InstagramSession {
16 |
17 | private SharedPreferences sharedPref;
18 | private Editor editor;
19 |
20 | private static final String SHARED = "Instagram_Preferences";
21 | private static final String API_USERNAME = "username";
22 | private static final String API_ID = "id";
23 | private static final String API_NAME = "name";
24 | private static final String API_ACCESS_TOKEN = "access_token";
25 |
26 | public InstagramSession(Context context) {
27 | sharedPref = context.getSharedPreferences(SHARED, Context.MODE_PRIVATE);
28 | editor = sharedPref.edit();
29 | }
30 |
31 | /**
32 | *
33 | * @param accessToken
34 | * @param expireToken
35 | * @param expiresIn
36 | * @param username
37 | */
38 | public void storeAccessToken(String accessToken, String id, String username, String name) {
39 | editor.putString(API_ID, id);
40 | editor.putString(API_NAME, name);
41 | editor.putString(API_ACCESS_TOKEN, accessToken);
42 | editor.putString(API_USERNAME, username);
43 | editor.commit();
44 | }
45 |
46 | public void storeAccessToken(String accessToken) {
47 | editor.putString(API_ACCESS_TOKEN, accessToken);
48 | editor.commit();
49 | }
50 |
51 | /**
52 | * Reset access token and user name
53 | */
54 | public void resetAccessToken() {
55 | editor.putString(API_ID, null);
56 | editor.putString(API_NAME, null);
57 | editor.putString(API_ACCESS_TOKEN, null);
58 | editor.putString(API_USERNAME, null);
59 | editor.commit();
60 | }
61 |
62 | /**
63 | * Get user name
64 | *
65 | * @return User name
66 | */
67 | public String getUsername() {
68 | return sharedPref.getString(API_USERNAME, null);
69 | }
70 |
71 | /**
72 | *
73 | * @return
74 | */
75 | public String getId() {
76 | return sharedPref.getString(API_ID, null);
77 | }
78 |
79 | /**
80 | *
81 | * @return
82 | */
83 | public String getName() {
84 | return sharedPref.getString(API_NAME, null);
85 | }
86 |
87 | /**
88 | * Get access token
89 | *
90 | * @return Access token
91 | */
92 | public String getAccessToken() {
93 | return sharedPref.getString(API_ACCESS_TOKEN, null);
94 | }
95 |
96 | }
--------------------------------------------------------------------------------
/android-instagram-oauth/src/br/com/dina/oauth/instagram/Main.java:
--------------------------------------------------------------------------------
1 | package br.com.dina.oauth.instagram;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | public class Main extends Activity {
7 |
8 | @Override
9 | public void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.main);
12 | }
13 |
14 | }
--------------------------------------------------------------------------------