Twitter (X) Login Setup Guide for Mobile App
This guide will help you set up Twitter (X) login in your MartFury mobile app.
Prerequisites
- A Twitter Developer Account
- A Twitter App created in the Twitter Developer Portal
- Basic knowledge of mobile app development
Step 1: Create a Twitter Developer Account
- Go to Twitter Developer Portal
- Sign in with your Twitter account
- Apply for a developer account if you haven't already
Step 2: Create a Twitter App
- In the Twitter Developer Portal, click "Create Project"
- Fill in your project details
- Select "Read and Write" permissions
- Create an app within your project
- Note down your API Key (Consumer Key) and API Secret Key (Consumer Secret)
Step 3: Configure Twitter App Settings
- Go to your app's settings in the Twitter Developer Portal
- Navigate to "User authentication settings"
- Enable "OAuth 2.0"
- Add the following callback URL:
martfury://twitter-auth
- Save your changes
Step 4: Configure Your Mobile App
Environment Variables
Create or update your .env
file with the following variables:
bash
TWITTER_CONSUMER_KEY=your_twitter_consumer_key
TWITTER_CONSUMER_SECRET=your_twitter_consumer_secret
TWITTER_REDIRECT_URI=martfury://twitter-auth
Replace your_twitter_consumer_key
and your_twitter_consumer_secret
with your actual Twitter API credentials.
iOS Configuration
The Twitter URL scheme is already configured in your Info.plist
. Make sure it contains:
xml
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>twitterkit-YOUR_TWITTER_API_KEY</string>
<string>martfury</string>
</array>
</dict>
</array>
Android Configuration
The Twitter configuration is already set up in your AndroidManifest.xml
. Make sure it contains:
xml
<activity
android:name="com.twitter.sdk.android.core.identity.OAuthActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<meta-data
android:name="com.twitter.sdk.android.CONSUMER_KEY"
android:value="@string/twitter_consumer_key" />
<meta-data
android:name="com.twitter.sdk.android.CONSUMER_SECRET"
android:value="@string/twitter_consumer_secret" />
And in your app's main activity:
xml
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="martfury" />
</intent-filter>
Step 5: Testing the Integration
- Run your app
- Go to the login screen
- Tap the X (Twitter) login button
- Complete the Twitter authentication flow
- Verify that you're redirected back to your app
Troubleshooting
Common Issues
Login fails with "Invalid callback URL"
- Verify that the callback URL in Twitter Developer Portal matches exactly:
martfury://twitter-auth
- Check that the URL scheme is properly configured in both iOS and Android
- Verify that the callback URL in Twitter Developer Portal matches exactly:
App crashes on Twitter login
- Verify that your Twitter API credentials are correct
- Check that all required configurations are in place
- Ensure you have an active internet connection
Getting Help
If you encounter any issues:
- Check the Twitter Developer Documentation
- Review the twitter_login package documentation
- Check your app's logs for detailed error messages
Security Considerations
- Never commit your Twitter API credentials to version control
- Always use environment variables for sensitive data
- Implement proper error handling and user feedback