-
Notifications
You must be signed in to change notification settings - Fork 10
Android users
Since this library uses AsyncTask library, the callbacks are made on the same background thread, which might not be good for android development (as far as updating UI is concerned).
You need to manually wrap your code into the runOnUiThread()
method inside every callback of the task.
What you can do is create a helper method that takes that AsyncTask as an argument and an interface as a callback.
public void callOnUIThread(AsyncTask task,MyCallback callback){
task.setOnCompleteCallback(new AsyncTask.OnCompleteCallback() {
@Override
public void onComplete(AsyncTask call) {
runOnUiThread(() -> {
if (call.isSuccessful)
callback.onSuccess(call.result);
else
callback.onFailure(call.exception);
});
}
});
}
Here, MyCallback is a helper interface for the callback.
You can also use Webview
for loggging into users account. Just create a webview and load https://errorxcode.github.io/docs/easyinsta-login/index.html
into it. After user click login, the page will be redirected to the user account with username and password in the query of procedding URL. Just use that username and password from there to login into the client.
Example:
public void login() {
Dialog dialog = new Dialog(this);
dialog.setTitle("Login into instagram");
WebView webview = new WebView(this);
webview.loadUrl("https://errorxcode.github.io/docs/easyinsta-login/index.html");
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
var link = new URL(url);
var query = link.getQuery();
System.out.println(query);
Toast.makeText(MainActivity.this, link.toString(), Toast.LENGTH_SHORT).show();
if (query.contains("username") && query.contains("password")) {
System.out.println(url);
var username = query.split("&")[0].split("=")[1];
var password = query.split("&")[1].split("=")[1];
try {
// here we login into instagram, dismiss the dialog
dialog.dismiss();
var loading = new ProgressDialog(view.getContext());
loading.setTitle("Logging in");
loading.setMessage("Please wait...");
loading.show();
Instagram.loginOrCache(getExternalCacheDir(), username, password);
loading.dismiss();
return true;
} catch (IGLoginException e) {
new AlertDialog.Builder(view.getContext())
.setTitle("Login failed")
.setMessage(e.getMessage())
.setPositiveButton("Try again", (dialog1, which) -> login())
.setNegativeButton("Cancel", (dialog12, which) -> finish())
.setCancelable(false)
.show();
}
} else
return false; // if user clicked on another link/button
} catch (MalformedURLException e) {
e.printStackTrace();
return false;
// never happens
}
return true;
}
});
dialog.setContentView(webview);
dialog.show();
dialog.getWindow().setLayout(500, 700);
}