JAVA:如何从facebook.com/l.php?u=提取YouTube网址 [英] JAVA : how to extract youtube URL from facebook.com/l.php?u=
问题描述
我米开发一个Android应用程序,
并且,在这一步,我想用脸谱用户的YouTube视频请求养活一个数据库,
当用户点击在从Facebook,意图捕捉的URL YouTube视频,但我发现,URL是这样的:
https://m.facebook.com/l.php?u=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DD148dv1G3E4&h=KAQGHuQwG&s=1&enc=AZNGSlqUPqFIDzzjZHddvdQlAkwGkAHJy7YxLMEX7Bfi7-1PE97FOtxHPq73XJ_mKf_Dh50D_YHBxrIiIJ1HnWCbesQO4f19EVtaV-ovXqHnXw
I m developing an Android app , and , in this step , I want to feed a database with a "Facebook user youtube video request", when a user click in a Youtube video from facebook , an intent catch the URL , but i found that URL is like that : https://m.facebook.com/l.php?u=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DD148dv1G3E4&h=KAQGHuQwG&s=1&enc=AZNGSlqUPqFIDzzjZHddvdQlAkwGkAHJy7YxLMEX7Bfi7-1PE97FOtxHPq73XJ_mKf_Dh50D_YHBxrIiIJ1HnWCbesQO4f19EVtaV-ovXqHnXw
有关这种原始的一种:
的 https://www.youtube.com/watch?v=D148dv1G3E4一> 的
For this original one : https://www.youtube.com/watch?v=D148dv1G3E4
我如何与JAVA(正则表达式或其他工具)的facebook.com/l.php?u= URL到www.youtube.com/watch?v=一个转换?
谢谢
How can I transform with JAVA (regex or other tool) the facebook.com/l.php?u= URL to the www.youtube.com/watch?v= one ? Thanks
推荐答案
在这个简单的例子,你可以以这样的:
In this simple example, you could to something like this:
String oldUrl = "https://m.facebook.com/l.php?u=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DD148dv1G3E4&h=KAQGHuQwG&s=1&enc=AZNGSlqUPqFIDzzjZHddvdQlAkwGkAHJy7YxLMEX7Bfi7-1PE97FOtxHPq73XJ_mKf_Dh50D_YHBxrIiIJ1HnWCbesQO4f19EVtaV-ovXqHnXw";
String newUrl;
List args= URLEncodedUtils.parse(oldUrl , Charset.defaultCharset());
for (NameValuePair arg:args) {
if (arg.getName().equals("u")) {
newUrl = URLDecoder.decode(arg.getValue(), "UTF-8");
}
}
首先,获得EN codeD YouTube网址,然后去code,并将其存放在NEWURL。
First, get the encoded youtube url, then decode it and store it in newUrl.
这篇关于JAVA:如何从facebook.com/l.php?u=提取YouTube网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!