首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >电话://网址追踪和goo.gl

电话://网址追踪和goo.gl
EN

Stack Overflow用户
提问于 2016-06-20 09:33:28
回答 1查看 254关注 0票数 1

我目前正在使用Goo.gl来跟踪我在互联网上发布的各种广告。我也想对电话号码链接做同样的事情(例如: href="tel:15555555555"),但是我完全不知道该怎么做。

我基本上是在尝试以一种免费的方式跟踪我的手机转换,我认为这是一个很好的选择,如果我能弄清楚的话……

有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2016-09-05 17:40:30

缩短网址使用Goo.gl在这里json数据发送在http头作为post请求。

在longUrl中使用重定向url方法发送变量

代码语言:javascript
复制
{'longUrl': 'https://www.google.com'}

该loginUrl作为http报头中的post请求发送,并且google.com最终被创建为缩短的url。

代码语言:javascript
复制
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:

代码语言:javascript
复制
{ "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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37913566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档