Help us understand the problem. What is going on with this article?

リンクを含むTweetができるURLを生成する (2系統のURLエンコード)

やりたいこと

  • Tweet Web Intentで使う以下のようなURLを得られるように、二重にURLエンコードしたいです。
    https://twitter.com/intent/tweet?text=%e3%83%86%e3%83%88%e3%83%a9%e3%83%a9%e3%83%9c+%23tetr4lab.&url=https%3a%2f%2ftetr4lab.nyanta.jp%2f%3ftext%3d%25E3%2581%2582%2520%25E3%2581%2584%25E3%2581%2586%2520%25E3%2581%2588%25E3%2581%258A

ポイント

  • 外側ではスペースは+に変換したいですが、内側ではスペースを%20に変換したいです。
  • System.Web.HttpUtility.UrlEncode ()UnityEngine.Networking.UnityWebRequest.EscapeURL ()は、+へ変換します。
  • System.Uri.EscapeUriString ()は、%20へ変換します。

コード

.NET

using System;
using System.Diagnostics;

void Sample () {
    var innerMessage = "あ いう えお";
    var innerUrl = $"https://tetr4lab.nyanta.jp/?text={Uri.EscapeUriString (innerMessage)}";
    var outerMessage = "テトララボ #tetr4lab.";
    var outerUrl = $"https://twitter.com/intent/tweet?text={Uri.EscapeDataString (outerMessage)}&url={Uri.EscapeDataString (innerUrl)}";
    Process.Start (outerUrl);
}

Unity

using System;
using UnityEngine;
using UnityEngine.Networking;

void Sample () {
    var innerMessage = "あ いう えお";
    var innerUrl = $"https://tetr4lab.nyanta.jp/?text={Uri.EscapeUriString (innerMessage)}";
    var outerMessage = "テトララボ #tetr4lab.";
    var outerUrl = $"https://twitter.com/intent/tweet?text={UnityWebRequest.EscapeURL (outerMessage)}&url={UnityWebRequest.EscapeURL (innerUrl)}";
    Application.OpenURL (outerUrl);
}

参考

どうもありがとうございました。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away