2016-06-20 67 views
1

我目前使用Goo.gl来跟踪我在互联网上发布的各种广告。我想用电话号码链接(例如:href =“tel:15555555555”)做同样的事情,但我完全不知道如何做到这一点。电话://网址跟踪和goo.gl

基本上,我想跟踪我的手机转换以免费的方式,我想这为如果我可以弄清楚一个很好的选择...

什么想法?

回答

-1

使用Goo.gl缩短网址 这里json数据在http头中作为post请求发送。通过使用重定向URL方法在longUrl

{'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"} 

你缩短URL是在JSON的 “ID” 参数。

来源:http://adityagoyal-java.blogspot.in/2016/09/shorten-url-using-googl-by-http-post.html