How to tweet both URL and Hashtags

2019-03-28 09:48发布

Following this example on another thread, I am able to tweet either the URL:

String tweetUrl = "https://twitter.com/intent/tweet?text=PUT TEXT HERE &url="
                        + "https://www.google.com";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));

which shows up as:

PUT TEXT HERE https://www.google.com

or the hashtags:

String tweetUrl = "https://twitter.com/intent/tweet?text=PUT TEXT HERE &url="
                        + "https://www.google.com &hashtags=android,twitter";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));

which shows up as:

PUT TEXT HERE #android #twitter

But for some reason, I am unable to show both the URL and the hashtags in the twitter box.

What am I doing wrong?

1条回答
聊天终结者
2楼-- · 2019-03-28 10:22

Answering my own question: There shouldn't be a space before &hashtags. In other words, the above should be written:

String tweetUrl = "https://twitter.com/intent/tweet?text=PUT TEXT HERE &url="
                        + "https://www.google.com&hashtags=android,twitter";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));

Hope this helps someone.

查看更多
登录 后发表回答