Rickybobby
Rickybobby

Reputation: 305

Where to put API key for Twitter Key for Android

I'm a little confused on where I need to place the API keys for the Twitter Kit for Android. Searching online mostly comes up with Fabric API, which i'm not using

According to the dev section on twitter, it says to put the key here: (https://dev.twitter.com/twitterkit/android/installation)

 Next, add your API key and secret to your application resources.

 <resources>
   <string 
 android:name="com.twitter.sdk.android.CONSUMER_KEY">XXXXXXXXXXX</string>
   <string 
 android:name="com.twitter.sdk.android.CONSUMER_SECRET">XXXXXXXXXXX</string>
 </resources>

Is this just going to be in the Strings.xml? It doesn't seem to like the android:name when it's in the string.xml file. It seems that Fabric API has their key put into the AndroidManifest file, as meta-data. This doesn't seem to be too clear on where it needs to be put. I'm assuming it's in the wrong area for me, as i can't get any tweets from the UserTimeLine to load.

Upvotes: 3

Views: 1597

Answers (2)

Aldo Wachyudi
Aldo Wachyudi

Reputation: 18001

I find the docs to be misleading as well. Maybe they will edit it in the future. Yes you can put it on strings.xml. You just have to omit the android prefix.

<resources>
    <string name="app_name">SampleTwitterClient</string>
    <string name="action_settings">Settings</string>

    <string name="com.twitter.sdk.android.CONSUMER_KEY">asdfasdf</string>
    <string name="com.twitter.sdk.android.CONSUMER_SECRET">asdfasdf</string>
</resources>

Adding it on AndroidManifest.xml meta-data won't work. It's used by Fabric, not Twitter SDK.

Upvotes: 4

Elias Fazel
Elias Fazel

Reputation: 2113

set this @onCreate of your target activity

TwitterConfig config = new TwitterConfig.Builder(this)
                .logger(new DefaultLogger(Log.DEBUG))
                .twitterAuthConfig(new TwitterAuthConfig(getString(R.string.CONSUMER_KEY), getString(R.string.CONSUMER_SECRET)))
                .debug(true)
                .build();
        Twitter.initialize(config);

Upvotes: 2

Related Questions