我目前正在使用Goo.gl来跟踪我在互联网上发布的各种广告。我也想对电话号码链接做同样的事情(例如: href="tel:15555555555"),但是我完全不知道该怎么做。
我基本上是在尝试以一种免费的方式跟踪我的手机转换,我认为这是一个很好的选择,如果我能弄清楚的话……
有什么想法吗?
发布于 2016-09-05 17:40:30
缩短网址使用Goo.gl在这里json数据发送在http头作为post请求。
在longUrl中使用重定向url方法发送变量
{'longUrl': 'https://www.google.com'}该loginUrl作为http报头中的post请求发送,并且google.com最终被创建为缩短的url。
public void sendPostBody() throws Exception {
String url = "https://www.googleapis.com/urlshortener/v1/url?key=YOUR_GENERATED_KEY"; //Generated your own key on your google account
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
// add header
post.setHeader("Content-type","application/json");
post.setEntity(new StringEntity("{'longUrl': 'https://www.google.com'}", "UTF8"));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(" The shorten Goo.gl Url is :::: "+result.toString());
}此结果包含如下格式的json:
{ "kind": "urlshortener#url", "id": "YourShorternURL", "longUrl": "https://www.google.com"} 您的Shorten URL是JSON中的"id“参数。
来源:http://adityagoyal-java.blogspot.in/2016/09/shorten-url-using-googl-by-http-post.html
https://stackoverflow.com/questions/37913566
复制相似问题