2016-06-20 3 views
1

현재 인터넷에 게시중인 다양한 광고를 추적하기 위해 Goo.gl을 사용하고 있습니다. 전화 번호 링크 (예 : href = "tel : 15555555555")를 사용하여 동일하게하고 싶습니다. 그러나이 작업을 수행하는 방법에 대해서는 완전히 분실했습니다.전화 번호 : // URL 추적 및 goo.gl

어떤 아이디어 ... 나는 기본적으로 무료 방법으로 내 전화 전환을 추적하기 위해 노력하고있어 및 난 그냥 그것을 알아낼 수 있다면 최고의 선택이 될 것으로이 생각?

답변

-1

Goo.gl을 사용하여 단축 URL 여기에서 json 데이터는 POST 요청으로 http 헤더에 전송됩니다. longUrl

{'longUrl': 'https://www.google.com'} 

이 loginUrl에서 URL 방식을 사용하여 리디렉션

송신 변수는 HTTP 헤더 포스트의 요청으로 전송하고 최종적 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