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
Critical Configuration
The MartFury app uses OAuth 1.0a (not OAuth 2.0). Incorrect settings will cause login failures with error code 302.
Go to your app's settings in the Twitter Developer Portal
Navigate to "User authentication settings" and click "Edit"
Configure the following settings exactly:
Setting Required Value App permissions Read and write Type of App Native App App info > Client type Public client Under "App info", add the callback URL:
martfury://twitter-authMake sure OAuth 1.0a is enabled (check under "Keys and tokens" tab)
Save your changes
Common Mistakes That Cause Error 302
- Setting "Type of App" to "Web App, Automated App or Bot" instead of "Native App"
- Setting "Client type" to "Confidential client" instead of "Public client"
- Using OAuth 2.0 only without enabling OAuth 1.0a
- Callback URL mismatch (must be exactly
martfury://twitter-auth)
Step 4: Configure Your Mobile App
Environment Variables
Create or update your .env file with the following variables:
TWITTER_CONSUMER_KEY=your_twitter_consumer_key
TWITTER_CONSUMER_SECRET=your_twitter_consumer_secret
TWITTER_REDIRECT_URI=martfury://twitter-authReplace 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. Verify it contains the martfury scheme:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>martfury</string>
</array>
</dict>
</array>Android Configuration
The Twitter configuration is already set up in your AndroidManifest.xml. Verify it contains:
- The OAuthActivity (for handling Twitter's OAuth flow):
<activity
android:name="com.twitter.sdk.android.core.identity.OAuthActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />- The intent-filter in your MainActivity (for handling the callback):
<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>:::note The app reads Twitter credentials from the .env file, not from AndroidManifest meta-data tags. You do NOT need to add CONSUMER_KEY or CONSUMER_SECRET meta-data to AndroidManifest. :::
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
1. Error 302 - "An error occurred (302)"
This is the most common error and is caused by incorrect Twitter Developer Portal settings.
Solution: Go to Twitter Developer Portal → Your App → User authentication settings → Edit, and verify:
| Setting | Must Be |
|---|---|
| Type of App | Native App (NOT "Web App, Automated App or Bot") |
| Client type | Public client (NOT "Confidential client") |
| OAuth 1.0a | Enabled |
| Callback URL | martfury://twitter-auth |
2. 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
martfuryis properly configured in both iOS (Info.plist) and Android (AndroidManifest.xml) - Make sure your
.envfile has:TWITTER_REDIRECT_URI=martfury://twitter-auth
3. App crashes on Twitter login
- Verify that your Twitter API credentials are correct in
.env - Check that
ENABLE_TWITTER_SIGN_IN=truein your.envfile - Ensure you have an active internet connection
- Check that OAuth 1.0a is enabled in Twitter Developer Portal
4. Twitter button not appearing
- Verify
ENABLE_TWITTER_SIGN_IN=truein your.envfile - Verify
TWITTER_CONSUMER_KEYandTWITTER_CONSUMER_SECRETare set - Restart the app completely (hot reload does not reload
.envchanges)
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
