3

Hey. I am developing an application using the Twitter4j api. In order to allow the application and get an access token, I launch the browser with the callback parameters which I had set in the manifest file.

<data android:scheme="scheme" android:host="authenticatorapp"></data> 

After allowing the application, the browser calls the following and fails with a not found message. scheme://authenticatorapp?oauth_token=n5vd99dfnmnf...

I tried it both on the emulator and the device. In the emulator, LogCat gives me this :

12-12 15:04:05.743: ERROR/browser(230): onReceivedError -10 scheme://authenticatorapp?oauth_token=Jj...M&oauth_verifier=3ZfuY... The protocol is not supported.

-- The manifest file :

    <activity android:name=".AuthenticatorApp"
        android:launchMode="singleInstance"
        >
        <intent-filter>         
            <category android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.LAUNCHER" />
            <data android:scheme="scheme" android:host="authenticatorapp"></data>                                
        </intent-filter>            
    </activity>

    <!-- Broadcast Receiver that will process AppWidget updates -->
    <receiver android:name=".ZaytungWidget" android:label="@string/widget_name">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />                             
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/tweet_metadata" />
    </receiver>
    <!-- Service to perform web API queries -->
    <service android:name=".ZaytungWidget$UpdateService" />
</application>

<uses-sdk android:minSdkVersion="4" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.INTERNET" />    

Orkun
  • 6,998
  • 8
  • 56
  • 103

3 Answers3

3

Can you please post the whole manifest file?

I found the following question which may be useful later on: OAuth instance state in Android

The question linked to the following example application, which may be helpful:

http://code.google.com/p/jpoco/source/browse/trunk/jpoco-android-app/AndroidManifest.xml

Community
  • 1
  • 1
Luke Dunstan
  • 4,862
  • 1
  • 17
  • 15
  • Thank you, I appended the manifest file, i couldnT be sure if i must have main action for example, since i am intending to start this from the widget. – Orkun Dec 12 '10 at 15:18
  • Wow it worked. Thanks! – Orkun Dec 12 '10 at 15:27
  • @Orkun: Interesting solution: I have a question just to confirm I understand correctly: you're having native app and getting the callback so that the user does not need to enter any Twitter OAuth Pin, is that right? For your app in twitter, when you registered it, did you set it as 'Desktop app' or 'Web app'? – Mathias Conradt Dec 13 '10 at 12:29
  • @Mathias: "you're having native app and getting the callback so that the user does not need to enter any Twitter OAuth Pin, is that right?" That s right. I wasnT quite sure whether the user would still need to enter any pin after the callback. And it turned out the catching the verifier from the uri suffices, just as you said. And I had registered as a Web App. – Orkun Dec 13 '10 at 15:31
  • Cool, I will also give it a try! – Mathias Conradt Dec 13 '10 at 15:47
  • One hopefully last question: if I want to register a call back url not starting with http, i.e. scheme://, I would get a message "You might be wanting to put a custom protocol in your callback url. Please leave this field blank and email us at api@twitter.com with your desired callback url and this application's consumer key and we'll add it for you." -- so you also had to contact twitter first? – Mathias Conradt Dec 13 '10 at 16:57
  • Hey! I believe you mean the application registration form on the Twitter developer site. If so, you can simply fill it with any valid URL and define actual callback in the manifest file. – Orkun Dec 15 '10 at 15:23
1

This is what I have in my working Manifest.xml, where org.gpsagenda.OAUTH is the activity doing the Authenticating.

        <activity android:name="org.gpsagenda.OAUTH" >
        <intent-filter>
            <action android:name="android.intent.action.VIEW"></action>
            <category android:name="android.intent.category.DEFAULT"></category>
            <category android:name="android.intent.category.BROWSABLE"></category>
            <data android:scheme="gpsagenda" android:host="twitt" />
        </intent-filter>
    </activity>
iarwain01
  • 424
  • 3
  • 11
0

If you're developing a native app, you don't use the callback parameters, but need to let the user enter the pin in your app somewhere - which he gets when you open the authorization_url in a browser or probably more comfortably within your app in a webview.

You could also automatically fetch the pin after the user has clicked on 'yes' in the authorization twitter webpage, but not sure if it's against the twitter ToS.

Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192