Now i try to Implement Twitter Integration in android using twitter4j library.Few months back I successfully implemented this using a dummy call back url like "PicPuzzle://tkxel".
But now Twitter changes its scheme and now not allow to create application with dummy URL.
Now the problem is after authentication It redirect to callbackurl But not return to application.
I specify the same url in application and registration page. I refered Problem in Callback in Twitter in Android and How I can call back in Android using OAuth for Twitter?. But these solutions are now not working because now twitter not allow to create application with dummy URL. Please help me to solve this problem.
Follow below steps:
Go to Twitter Apps: https://apps.twitter.com/
Then, Go to your app.
Go to Settings Tab
In section "Callback URLs", add the below line:
twittersdk://
Click button "Update Settings" at the bottom. That's it.
Hope this works!
Create your own WebViewClient subclass.
Override shouldOverrideUrlLoading(WebView view, String url) method.
In shouldOverrideUrlLoading(), check if url.startsWith(YOUR_CALLBACK_URL) is true.
If true, retrieve "oauth_verifier" parameter from the URL and return true (true from shouldOverrideUrlLoading() prevents the WebView instance from loading the URL).
Get an access token using the value of the parameter obtained in the step 4.
Your application can get control back from the WebView instance after the step 4.
If the above steps sound cumbersome, try TwitterOAuthView. Its usage is very simple. Just call
view.start(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL, true, listener);
and receive the result via TwitterOAuthView.Listener interface defined as below.
void onSuccess(TwitterOAuthView view, AccessToken accessToken);
void onFailure(TwitterOAuthView view, TwitterOAuthView.Result result);
If true is given to TwitterOAuthView.start() method as the forth argument, TwitterOAuthView does not access the callback URL, and I think this behavior is what you want to implement. The source code, TwitterOAuthView.java, may be of help.
Related
I'm working on an app with a custom url scheme.
It is opening some webpage for authentication in a chrome tab. This is done in xamarin forms like this:
Browser.OpenAsync(apiUrl + "mobile", new BrowserLaunchOptions
{
LaunchMode = BrowserLaunchMode.SystemPreferred,
TitleMode = BrowserTitleMode.Hide,
});
everything work as expected if I return a webpage with a link and click the the link manually:
Click here to go the app
But if i return a 302 redirect to the same url it will not close the chrome tab and dont focus the app again.
If i add a javascript in the response, it will not automatically open the url (close the chrome tab and focus the app)
I've tried things like this:
window.location = url;
window.open(url,'_self');
setTimeout(()=>window.open(url,'_self'),10);
(url is a valid variable, even tried alert(url) after changing the location and it show the correct url.
Why does it only work when I click the link manually?
In order to maintain the user's security and experience, the browser prohibits the direct use of window.open(URL) in JS to open new links.
Try to change like below:
setTimeout(()=>window.open(url,'_self'),500); //The delay time must not be too short or you will be intercepted
I'm developing an Android application which requires Flickr API integration. In previous days, I was able to successfully complete the oauth process. But now its not working, and I strongly believe it happend after flickr APIs changed from http:// to https://
Let me explain the situation..
I'm following the steps explained in Flickr API Doc
As a result of the call to http://www.flickr.com/services/oauth/request_token API, I'm successfully receiving the oauth_token.
After this step, I'm presenting Flickr authorization page in a webview with the url specified in API doc (which is somthing similar like, https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432, and of-course, with the oauth_token which I received in the previous step)
Few days before this call was working when I'm using http:// instead of https://. But now, both http:// and https:// are not working. The page is displaying the login screen, but after successful login, the page is not redirecting to the grant access page, instead it is just redirecting to the Flickr Home page. And hence, I'm unable to grant access and unable to receive the oauth_verifier.
Hope I'm well explaining the situation which I'm facing now. But in short, Flickr Login for my application is not working, and I'm running out of time... :(
So, Geeks, Please give some light on the issue...
--Thanks in advance.
I got the same problem. I was using the connection in a WebView and my code was using the "http" protocol in the request.
I could resolve the issue by first using the "https" protocol for the authentification URL. As you say just doing that did not work. So I change the call of the url that was in the WebView and used the ACTION_VIEW intent and it worked.
Calling :
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(AuthentificationPath)));
Don't forget to implement the OnResume() function of your Activity to get the data of the returned intent.
Of course it is just a workaround but it does the job if you have to be fast.
Hope it helps!
Still the issue is there, After oauth Flickr is not redirecting to grant_access page. But I need to get the oauth process successfully completed in my on-going project, as soon as possible. So I have done a workaround to solve the issue.
To solve the 'not redirecting' issue, I have done a little bit change in my WebView's WebViewClient implementation. It's nothing great, but just redirecting to authorize page again, after successful login.
Authorize URL Example : https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432
So, given below is the detailed implementation of WebViewClient:
mAuthWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
showProgressDialog();
/** TODO: This part should be deleted after flickr fixes the oauth redirection issue */
if(url.endsWith("flickr.com/")) {
mAuthWebView.loadUrl("https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432");
return;
}
/* After successful login the redirected url will contain a parameter named 'oauth_verifier' */
if (url.indexOf("oauth_verifier=") > -1) {
/* Get the 'oauth_verifier' parameter from url and do next steps */
performLoginSuccess();
}
}
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (url.contains(_my_redirect_url_) && !url.contains("oauth_verifier=")) {
/* User not authenticated our app */
finish();
} else if (!url.contains("oauth_verifier=")) {
killProgressDialog();
}
}
});
After loading the authorization url, the web view will take the user to login page, and after user successfully loged into Flickr, with web vew client implementation we are again loading the authorization url, to present the grant access page.
mAuthWebView.loadUrl("https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432");
I know, this is not the right way to do this...
Any better solutions are always welcome.... :)
i'm trying to connect twitter for android. so I have downloaded the source from github. but i got a message, which is
<error>Desktop applications only support the oauth_callback value 'oob'</error>
but i already have defined it. 'public static final String REST_CALLBACK_URL = "hywtest://hywtwitter";'
i change callback_url to 'oob', i can come close to twitter, but when change a page, show pin number, and there's nothing happens.
of course, i have changed manifest too.
<data
android:host="hywtwitter"
android:scheme="hywtest" />
please help me!
You have to provide a callback URL in your Twitter Application Page in Application Details where twitter return after successful authentication.
You need to provide a placeholder callback URL on your application record on dev.twitter.com -- this placeholder allows you to perform callback-based auth with a dynamically supplied callback on the oauth/request_token step.
I have a webview in Android app and load my webapplication. I am listening the page navigation using ShouldOverrideURL method and do some operation. I want to do specific operation when the URL method type is GET or POST. I cannot use PostURL method here as I load only one home URL.
It looks like shouldOverrideUrl is only called during GET requests: Android - how to intercept a form POST in android WebViewClient on API level 4
If you want to do a specific operation during a POST operation for a particular URL, you want to extend WebView and override WebView#postUrl(String url, byte[] postData).
Stuck on an issue with http post data.
So we've created a webview to work in.
Then called a third party webservice this ask's to provide a postback url and some parameters, the webservice then processes the paramaters and redirects the user (our app) to the postback url we provided, with some data as a http post.
We want to get the post data from this postback url but within the webview or within our app.
Tried intercepting the url load with this code:
final WebView webview = new WebView(this);
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Grab data here...
return super.shouldOverrideUrlLoading(view, url);
}
});
However can't seem to find any objects or methods to gain access to the data within this method.
The other attempt was to give them the postback url as an intent within our app like:
myscheme://someText/someParam
this would have started a new activity when the postback is called (as we have set up an intent-filter within our android-manifest), this intent fires up our app activity within a browser but not within our webview, but anyway again we can't see how to access the post data from this.
Thanks for looking,
Any ideas?
Didn't find a way to do this. Basically can't get at data posted at a webview or a browser intent.
Instead the solution we went with is:
Postback to a server, get the postdata here (PHP) and save in a DB, then retrieve the data from this DB within the phone.