top of page

[flutter/dart]Open the Twitter DM page from the smartphone app


Overview


When creating a smartphone app with flutter, you may want to open other apps directly. This time, I will show you how to open a specific Twitter account and how to open a DM page.



Method


Use the url_launcher package. If you pass a url as an argument to the launch () method of this package, it will open that url.

static String _url ='https://www.rm48.net';
if (await canLaunch(url)) {
  await launch(url);
  return true;
}

If you pass the url of the app corresponding to this url part, it will open in the appropriate app. You can find out what kind of url you should pass by googled with "xxx url scheme".


Some people have already put together the twitter url scheme (here).

In the case of twitter, there are two methods, one is to open it on a smartphone app and the other is to open it on a website. Like the above site, URLs starting with

'twitter: //'

are opened in the twitter app.


URLs starting with

'https://twitter.com/'

will be opened on the web page.


First try to open it with the application, and if it is not installed, I think it is better to open it on the web. (See here for details)


In case of ios, you need to add twitter to info.plist.

<key>LSApplicationQueriesSchemes</key>
<array>
   <string>twitter</string>
   <string>https</string>
</array>


Open a Twitter account page


This is the same as the above page.

//url of the app
String app_url="twitter://user?id=1293878995730051074";
//url of web
String web_url="https://twitter.com/RM65120470";

if (await canLaunch(app_url)) {
  await launch(app_url);
}
else {
  if (await canLaunch(web_url)){
    await launch(web_url);
    return true;
  }
  else{
    return false;
  }  
}

By the way, the number at id = is different from @ *** that appears on the profile page of twitter, so be careful (I struggled this for about an hour). (Click here for details)



Open Twitter DM page


This is what I mainly wanted to do with my app. When I received an inquiry about the app, I wanted to go directly to the page that sends DM to my account.

However, the URL to the page to send the DM is not summarized in the above summary.

(By the way, 'twitter: // messages' in the above summary will open the DM page of your account)


After all, do as follows.


//web url
static const String twitter_dm_url="https://twitter.com/messages/compose?recipient_id=1293878995730051074";

//app url
static const String twitter_dm_app="twitter://messages/compose?recipient_id=1293878995730051074";

//same as below

Please set recipient_id = the id of the account you want to send DM to.



Recent Posts

See All

[Flutter/Dart] Format string with TextField

What want to do I want to create an input form using TextField. For example, if the input content is a monetary amount, I would like to display it in 3-digit delimiters with a ¥ prefix. Rather than ha

Comments


Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png
bottom of page