javaandroidhttp-redirectfeedly

Android: display a web page and letting user login to get the feedly access token


I am trying to write an Android app to access and display Feedly subscriptions to the user.

For this purpose , I need to post a URL to Feedly API and in return it send back HTML code for login page.

URL example to post:

https://sandbox7.feedly.com/v3/auth/auth?client_id=sandbox&redirect_uri=http%3A%2F%2Flocalhost&scope=https://cloud.feedly.com/subscriptions&response_type=code

Here, I use http://localhost as redirect URI because I am not hosting anything for this application.

after the user logs in, Feedly API redirects a code to http://localhost

Now, I have 2 issues: 1. I don't know how to display the web page for login on Android. How can I do that and let the user login ? What is the best practice for such purpose ? 2. How can I get the access token which is sent back to the redirect URI as a parameter ?

for the first question maybe I can use webview as suggested in another question. How to display a webpage in android?

BUT then how shall I get the code returning to the redirect_uri ?

Thanks.


Solution

  • I solved this by calling mobile browser with correct URL:

    String url = "http://cloud.feedly.com/v3/auth/auth?client_id=xxxx&redirect_uri=myownuri%3A%2F%2F&scope=https://cloud.feedly.com/subscriptions&response_type=code";
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    startActivity(i);
    finish();
    

    and then fetching the redirected URL by registering a custom URI in the manifest file:

    <activity
        android:name=".BrowserActivity"
        android:label="Feedly Login" >
       <intent-filter>
            <data android:scheme="myownuri" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity>
    

    then I parse the returned parameter in my activity :

    Uri data = this.getIntent().getData();
    if (data != null && data.isHierarchical()) {
        String url = this.getIntent().getDataString();