For iOS Twitter Composer not working in TwitterKit 3.0.3

ios

#1

i am using this code

// Swift
let composer = TWTRComposer()
composer.setText("just setting up my Twitter Kit")
composer.setImage(UIImage(named: "twitterkit"))

// Called from a UIViewController
composer.show(from: self.navigationController!) { (result in
  if (result == .done) {
     print("Successfully composed Tweet")
  } else {
    print("Cancelled composing")
  }
}

i am encountering this error

[TwitterKit] did encounter error with message “Error obtaining user auth token.”: Error Domain=TWTRLogInErrorDomain Code=-1 “<?xml version="1.0" encoding="UTF-8"?>

Desktop applications only support the oauth_callback value ‘oob’
/oauth/request_token

” UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?>

Desktop applications only support the oauth_callback value ‘oob’
/oauth/request_token

}


#2

Have you initialized Twitter Kit and do you have a logged-in user session?


#3

Thanks for your reply

Yes i initialized TwitterKit in AppDelegate
like this

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Twitter.sharedInstance().start(withConsumerKey:"hTpkPVU4pThkM0", consumerSecret:"ovEqziMzLpUOF163Qg2mj")

    return true
}

and when i check logged-in user session like this the condition which is satisfied which is the else section and hence printing the “Not Login”

if(Twitter.sharedInstance().sessionStore.hasLoggedInUsers()){
            self.composeTweet()
        }else{
            Twitter.sharedInstance().logInWithCompletion {
                (session, error) -> Void in
                if (session != nil) {
                    
                    print(session!.userID)
                    print(session!.userName)
                    print(session!.authToken)
                    print(session!.authTokenSecret)
                    self.composeTweet()
                    
                    
                }else {
                    print("Not Login")
                }
            }

}

and now i manually installed TwitterKit in a test project in this test project when i checking the login session its encounter the error:

[TwitterKit] did encounter error with message “Error obtaining user auth token.”: Error Domain=TWTRLogInErrorDomain Code=-1 “<?xml version="1.0" encoding="UTF-8"?>

Desktop applications only support the oauth_callback value ‘oob’
/oauth/request_token

” UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?>

Desktop applications only support the oauth_callback value ‘oob’
/oauth/request_token

}


#4

i followed this installation step for setup.
https://dev.twitter.com/twitterkit/ios/installation

And for compos tweet this steps

Compose Tweets


#5

Same problem with iOS 11 and TwitterKit 3.1.0

Configuration:

  • iPhone 5s, iPad Air
  • iOS 11 beta 6.
  • TwitterKit 3.1.0
  • New empty project. TwitterKit installed manually. Followed all steps from TwitterKit docs.

Case 1: Twitter App did NOT INSTALLED from AppStore

Code from TwitterKit docs:

import UIKit
import TwitterKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        if (Twitter.sharedInstance().sessionStore.hasLoggedInUsers()) {
            // App must have at least one logged-in user to compose a Tweet
            let composer = TWTRComposerViewController.emptyComposer()
            present(composer, animated: true, completion: nil)
        } else {
            // Log in, and then check again
            Twitter.sharedInstance().logIn { session, error in
                if session != nil { // Log in succeeded
                    let composer = TWTRComposerViewController.emptyComposer()
                    self.present(composer, animated: true, completion: nil)
                } else {
                    let alert = UIAlertController(title: "No Twitter Accounts Available", message: "You must log in before presenting a composer.", preferredStyle: .alert)
                    self.present(alert, animated: false, completion: nil)
                }
            }
        }
    }


}

Produces non-closable alert:

And error in console:

[TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <error>Desktop applications only support the oauth_callback value 'oob'</error>
  <request>/oauth/request_token</request>
</hash>
" UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <error>Desktop applications only support the oauth_callback value 'oob'</error>
  <request>/oauth/request_token</request>
</hash>
}

Case 2: Twitter App did INSTALLED from AppStore

Same code open Twitter App with connection dialog. Then go back to the TestApp and present Composer and successfully post one time. Second time, after checking if(Twitter.sharedInstance().sessionStore.hasLoggedInUsers()) { … – nothing happens.

So, i found only one way for successfully share something with twitter composer:

  • Logout from any twitter accounts
  • Login with connection dialog in TwitterApp
  • Call twitter composer

If you have not install TwitterApp catch the non-closable alert…


#6

Hey @Mikhail2000 Did you add a dummy callback URL in your app configuration? You also need to make sure you have read/write permissions.


#7

Ok. I got login dialog after adding http://localhost/ here:


All works on test project when i call it on viewDidLoad:.
But when i try to share some content with UIActivity and call it on prepareWithActivityItems:

- (void)prepareWithActivityItems:(NSArray *)activityItems
{
        if ([[Twitter sharedInstance].sessionStore hasLoggedInUsers]) {
            TWTRComposerViewController *composer = [TWTRComposerViewController emptyComposer];

            [self.parentVC presentViewController:composer animated:YES completion:nil];
        } else {
            [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
                if (session) {
                    TWTRComposer *composer = [[TWTRComposer alloc] init];
                    [composer showFromViewController:self.parentVC completion:^(TWTRComposerResult result) {
                        DDLogInfo(@"%ld", (long)result);
                    }];
                } else {
                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"No Twitter Accounts Available" message:@"You must log in before presenting a composer." preferredStyle:UIAlertControllerStyleAlert];
                    [self.parentVC presentViewController:alert animated:YES completion:nil];
                }
            }];
        }

catch in console Warning: Attempt to present <UINavigationController: 0x10307ce00> on <ActivityViewController: 0x1030e2600> whose view is not in the window hierarchy!
I tried to set self.parentVC any exist VCs. Tried [UIApplication sharedApplication].keyWindow.rootViewController. Every time i catch this warning, such something in TwitterKit ignore my VCs arguments and try to get top VC inside, but every time gets UIActivityVC, that really “not in the window hierarchy!”


#8

Hey @Mikhail2000

I played around with this in a test project myself. I found that putting this logic inside completionWithItemsHandler might give you the functionality you’re looking for.

Let me know if that helps!


#9

Great thanks. With completionWithItemsHandler: works almost perfect. Now i have a problem with autolayout:

[LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x1c04951d0 UIImageView:0x15dee9040.height <= 100   (active)>",
    "<NSLayoutConstraint:0x1c069de20 UIImageView:0x15dee9040.centerY == TSETweetImageAttachmentView:0x1618098c0.centerY   (active)>",
    "<NSLayoutConstraint:0x1c04960d0 V:|-(5)-[UIImageView:0x15dee9040]   (active, names: '|':TSETweetImageAttachmentView:0x1618098c0 )>",
    "<NSLayoutConstraint:0x1c069d880 V:|-(0)-[TSETweetImageAttachmentView:0x1618098c0]   (active, names: '|':TSETweetAttachmentView:0x15def2770 )>",
    "<NSLayoutConstraint:0x1c069dd80 TSETweetImageAttachmentView:0x1618098c0.bottom == TSETweetAttachmentView:0x15def2770.bottom   (active)>",
    "<NSLayoutConstraint:0x1c4687f30 V:[UILabel:0x1618092f0'25']-(10)-[TSETweetAttachmentView:0x15def2770]   (active)>",
    "<NSLayoutConstraint:0x1c4687fd0 TSETweetAttachmentView:0x15def2770.bottom == UILayoutGuide:0x1c01ad660'UIViewLayoutMarginsGuide'.bottom   (active)>",
    "<NSLayoutConstraint:0x1c46882f0 TSETweetTextView:0x15e9d6800'\U2018Antifa, mass media & Cli...'.top == UILayoutGuide:0x1c01ad660'UIViewLayoutMarginsGuide'.top - 10   (active)>",
    "<NSLayoutConstraint:0x1c4688480 TSETweetTextView:0x15e9d6800'\U2018Antifa, mass media & Cli...'.height == 111.38   (active)>",
    "<NSLayoutConstraint:0x1c46887a0 UILabel:0x1618092f0'25'.bottom == TSETweetTextView:0x15e9d6800'\U2018Antifa, mass media & Cli...'.bottom   (active)>",
    "<NSLayoutConstraint:0x1c0495ef0 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x1c01ad660'UIViewLayoutMarginsGuide']-(8)-|   (active, names: '|':UITableViewCellContentView:0x15ff621a0 )>",
    "<NSLayoutConstraint:0x1c0494eb0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x15ff621a0.height == 237.5   (active)>",
    "<NSLayoutConstraint:0x1c0495f40 'UIView-topMargin-guide-constraint' V:|-(8)-[UILayoutGuide:0x1c01ad660'UIViewLayoutMarginsGuide']   (active, names: '|':UITableViewCellContentView:0x15ff621a0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1c04951d0 UIImageView:0x15dee9040.height <= 100   (active)>

It happens when i set text, url and image for TWTRComposer instance.


#10

@Mikhail2000

Does this break the actual layout for you? Could you upload a screenshot of what you see on screen?

Thanks!


#11

No, just warning in console. Layout is ok. App waiting for review now. If something will broke i give you know. Thanks!