Multiline string problem for twitter API in Dart

Asked

Viewed 32 times

-2

I’m creating a bot that tweets on Dart. I’m having problems because I want to post with line break but I can’t, the following error appears when I try to convert a string into json through the twitter_api package:

When I assign the string to 'status' it gives this error

here is part of my code:

void tweetBuild(Map twitterKeys) async {
  final String _tweetText = "In this part comes the tweet text, when I put \n, it doesn't works";

  final _twitterOauth = new twitterApi(
  consumerKey: twitterKeys['apiKey'],
  consumerSecret: twitterKeys['apiKeySecret'],
  token: twitterKeys['accessToken'],
  tokenSecret: twitterKeys['acessTokenSecret']
  );

  Future tweetRequest = _twitterOauth.getTwitterRequest(
    'POST',
    'statuses/update.json',
    options: {
        'status' :  _tweetText
    }
    );

    var response = await tweetRequest;
    print(response.statusCode);
    print(response.body);

 }
  • Tried to do the url-Match of your message with Uri.encodeFull(_tweetText);? Remember to import the respective library (Dart:core).

  • when it is posted, on twitter, it does not convert back, so it will all code

1 answer

0

I don’t know about that package then because I never used it. But, as you are creating the String in Dart, it is necessary to escape the character \, then for each \ add one more \\:

final String _tweetText = "In this part comes the tweet text, when I put \\n, it doesn't works";
  • If I do this, the error continues, good looking, only changes the index

Browser other questions tagged

You are not signed in. Login or sign up in order to post.