Foursquare入住

时间:2011-12-29 11:40:29

标签: android foursquare

我在Android工作。我完成了Android应用程序中Foursquare集成所需的几乎所有工作。

现在我正在尝试在此应用程序中添加签入功能。

这是我用于foursquare签到的android代码:

URL url = new URL("https://api.foursquare.com/v2/checkins/add?venueId=4d6a73bafd7ea35d0c08b24a&shout=great....&broadcast=public&oauth_token=myauthtoken");
URLConnection conn = url.openConnection();

请告诉我,我做得对不对?实际上我不知道在我们的Android应用程序中通过Foursquare为场地添加检查功能的过程是什么。

3 个答案:

答案 0 :(得分:2)

我解决了我的问题: -

    try {

                     HttpPost post = new 
   HttpPost("https://api.foursquare.com/v2/checkins/add?venueId="+mNearbyList.get(position).id+"&shout=great....&broadcast=public&oauth_token="mytoken");



                        HttpClient hc=new DefaultHttpClient();
                        HttpResponse rp = hc.execute(post);
                    //    Log.v(TAG,"response from server "+EntityUtils.toString(rp.getEntity()));  
                          if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) 
                         {
                              Toast.makeText(PlacetoCheckin.this, "Done", Toast.LENGTH_SHORT).show();
                              String response = EntityUtils
                                .toString(rp.getEntity());
                        Log.v(TAG,
                                "response from server====="
                                        + response);
                          }
               }
               catch(Exception e){}
              }
            });

答案 1 :(得分:1)

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;

DefaultHttpClient httpClient;
HttpContext localContext;
private String ret;
HttpResponse response = null;
HttpPost httpPost = null;

public String sendPost(String url, List<NameValuePair> data, String contentType) {
    ret = null;

    httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);

    httpPost = new HttpPost(url);
    response = null;

    StringEntity tmp = null;

    httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1");
    httpPost.setHeader("Accept", "text/html,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");

    if (contentType != null) {
        httpPost.setHeader("Content-Type", contentType);
    } else {
        httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
    }

    try {
        tmp = new UrlEncodedFormEntity(data);
    } catch (UnsupportedEncodingException e) {

    }

    httpPost.setEntity(tmp);
    response = httpClient.execute(httpPost, localContext);


    if (response != null) {
        ret = EntityUtils.toString(response.getEntity());
    }


    return ret;
}

尝试使用此方法发布带有空ArrayList和null contentType的签入网址。

答案 2 :(得分:0)

Google Code上有一些旧的Android代码,由FourSquare编写,用于Android FourSquare应用。也许你可以在那里找到一些例子。

以下是链接:http://code.google.com/p/foursquared/source/browse/#hg