FourSquare를 사용하여 체크인 할 때 사진을 업로드해야합니다. 아무도하지 않았다면 매개 변수를 전달하는 데 도움이됩니다. FourSquare Offical Document : https://developer.foursquare.com/docs/photos/add을 참조했습니다. 지난 3 개의 매개 변수에 문제가 있습니다. 사전에 .- 고마워했을 경우를 제공 할 필요가 없습니다FourSquare 사진은 Android로 체크인 할 때 업로드됩니다.
0
A
답변
3
매개 변수는 postUrl
, postContentId
및 postText
는 선택 사항입니다 ... 제발 도와주세요. postUrl
및 postContentId
은 사진에서 더 많은 정보를 얻을 수있는 링크를 제공하는 데 사용됩니다. postText
은 사진에 대한 간단한 설명입니다.
0
/* * 내가 성공적으로 아래의 코드를 통해 포 스퀘어에 이미지를 업로드 */
todaydate = Latest Date;
venueId = The Venue Id is important.
URL = The image url from which the image will be downloaded to sd card;
foursquare = new Foursquare(
"Your Client Id", //*client id
"Your Client Secret", //*client secret
"Callback Url");
foursquare.authorize(ActivityName.this, new FoursquareAuthenDialogListener());
// Creates Bitmap from InputStream and returns it
private Bitmap downloadImage(String url) {
Bitmap bitmap = null;
InputStream stream = null;
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
try {
stream = getHttpConnection(url);
bitmap = BitmapFactory.decodeStream(stream, null, bmOptions);
stream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
return bitmap;
}
// Makes HttpURLConnection and returns InputStream
private InputStream getHttpConnection(String urlString)
throws IOException {
InputStream stream = null;
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
try {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
httpConnection.setRequestMethod("GET");
httpConnection.connect();
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
stream = httpConnection.getInputStream();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return stream;
}
@SuppressLint("SdCardPath")
private class FoursquareAuthenDialogListener implements DialogListener {
@Override
public void onComplete(Bundle values) {
foursquareAccessToken = Foursquare.mAccessToken;
//Toast.makeText(getApplicationContext(), "TOKEN: " + foursquareAccessToken, Toast.LENGTH_LONG).show();
new downloadUploadedImage().execute();
}
@Override
public void onFoursquareError(FoursquareError e) {
// TODO Auto-generated method stub
}
@Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
}
}
/*
* downloadUploadedImage Class will download image from url and convert to bitmap image,
* using that bitmap image then convert it to file and get the file path from sd card
* to upload image to fs from sdcard.
*/
public class downloadUploadedImage extends AsyncTask<String, Void, String>{
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = ProgressDialog.show(MyActivityName.this, "", "Posting Image to Foursquare...", true);
}
@Override
protected String doInBackground(String... params) {
bitMapImage = downloadImage(URL);
writeExternalToCache(bitMapImage, file);
return null;
}
@Override
protected void onPostExecute(String result){
super.onPostExecute(result);
if(file.exists()){
//Toast.makeText(getApplicationContext(), "PIC PATH: " + file.toString(), Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), "PIC PATH: " + picPATH, Toast.LENGTH_LONG).show();
picturePath = file.toString();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(picturePath,options);
final int REQUIRED_SIZE=200;
//Find the correct scale value. It should be the power of 2.
int scale=1;
while(options.outWidth/scale/2>=REQUIRED_SIZE && options.outHeight/scale/2>=REQUIRED_SIZE)
scale*=2;
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
preview_bitmap = BitmapFactory.decodeFile(picturePath,o2);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
preview_bitmap.compress(CompressFormat.JPEG, 75, bos);
fileContent = bos.toByteArray(); //byte array static byte[] fileContent;
new UploadImageToFsProfile().execute();
} else {
//Toast.makeText(getApplicationContext(), "Image not exist in sdcard.", Toast.LENGTH_LONG).show();
}
}
}
public class UploadImageToFsProfile extends AsyncTask<String, Void, String>{//params,progress,result
@Override
protected void onPreExecute(){
super.onPreExecute();
}
@SuppressWarnings("deprecation")
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://api.foursquare.com/v2/photos/add");
try
{
@SuppressWarnings("deprecation")
/*
* To use MultipartEntity class use httpclient-X.x.jar , httpcore-X.x.jar ,httpmime-X.x.jar
* and apachemime4jcore-X.x.jar
*/
MultipartEntity entity = new MultipartEntity();
entity.addPart("v", new StringBody(todaydate));
entity.addPart("venueId", new StringBody(venueId));
entity.addPart("public", new StringBody("1"));
entity.addPart("oauth_token", new StringBody(foursquareAccessToken));
ByteArrayBody imgBody = new ByteArrayBody(ChFsLogin.fileContent, "image/jpeg", "FS_image");
entity.addPart("image",imgBody);
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
responseResult = inputStreamToString(response.getEntity().getContent()).toString();
}
catch (ClientProtocolException e)
{ }
catch (IOException e)
{ }
return responseResult;
}
@Override
protected void onPostExecute(String result){
super.onPostExecute(result);
dialog.dismiss();
System.out.println("RES"+responseResult);
JSONObject obj;
try {
obj = new JSONObject(result);
//JSONArray meta =
obj = obj.getJSONObject("meta");
code = obj.getInt("code");
if(obj.has("errorDetail")){
Toast.makeText(getApplicationContext(), obj.getString("errorDetail"), Toast.LENGTH_LONG).show();
}
//Toast.makeText(getApplicationContext(), "code:"+code, Toast.LENGTH_LONG).show();
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (code ==200) {
Toast.makeText(getApplicationContext(), "Your Image Has Successfully Posted to FourSquare.", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Unable to Post Image to FourSquare.", Toast.LENGTH_LONG).show();
}
File fileToDelete = new File(file.toString());
boolean deleted = fileToDelete.delete();
if (deleted) {
} else {
}
}
private StringBuilder inputStreamToString(InputStream is) {
String rLine = "";
StringBuilder answer = new StringBuilder();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
try {
while ((rLine = rd.readLine()) != null) {
answer.append(rLine);
}
}
catch (IOException e) {
e.printStackTrace();
}
return answer;
}
}
0
libs와 폴더 프로젝트와 작업 파일에 나중에 코드에 정사각형 SDK 파일을 넣어 :
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://api.foursquare.com/v2/photos/add");
try
{
MultipartEntity entity = new MultipartEntity();
entity.addPart("v", new StringBody("20121210"));
entity.addPart("venueId", new StringBody(venue.getId()));
entity.addPart("public", new StringBody("1"));
entity.addPart("oauth_token", new StringBody(mAccessToken));
ByteArrayBody imgBody = new ByteArrayBody(bitmapdata, "image/jpeg", "FS_image");
entity.addPart("image",imgBody);
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
Log.v("response","" +response);
responseResult = inputStreamToString(response.getEntity().getContent()).toString();
}
catch (ClientProtocolException e)
{
Log.d(TAG, "Opening URL " +e);
}
관련 문제
- 1. 체크인 api foursquare
- 2. Foursquare 체크인 위치 피드
- 3. Foursquare API를 통해 체크인 할 때 여기에 표시되지 않습니다.
- 4. Facebook iPhone SDK Foursquare Place에 체크인
- 5. Foursquare 체크인 기능을 웹 사이트에 추가 할 수 있습니까?
- 6. Foursquare 푸시 알림
- 7. foursquare 나 gowalla와 같은 앱이 체크인 기능을 어떻게 구현합니까?
- 8. Android : foursquare api를 사용하여 체크인 장소에 대한 의견을 말하기
- 9. TFS에서 체크인 할 때 알림을 얻는 방법
- 10. Foursquare API 실시간 체크인 ... 장소 사진을 얻는 방법?
- 11. Foursquare 체크인 알림에 일관된 점수가 표시되는 방식은 무엇입니까?
- 12. Foursquare checkins
- 13. FourSquare 브랜드 사용 설명
- 14. 여러 파일이 grails로 업로드됩니다.
- 15. php $ _files가 계속 업로드됩니다.
- 16. Foursquare 장소 배제
- 17. 파일을 Android로 업로드 할 때 파일의 이름을 바꾸려면 어떻게합니까?
- 18. iPhone 그래픽을 Android로 포팅 할 때 경험 법칙이 있습니까?
- 19. Eclipse에서 Android로 배포 할 때 각 클래스의 앱 아이콘을 표시합니다.
- 20. 목표 C 걸릴 사진은
- 21. foursquare 개최지 id를 얻는 것
- 22. 여러 파일이 html 형식으로 업로드됩니다.
- 23. Foursquare Checkin의 유효성을 어떻게 확인합니까?
- 24. 권한이 사진은 안드로이드에
- 25. Xcode의 사진은 어떻게 분류됩니까?
- 26. 대용량 파일이 웹 브라우저에 업로드됩니다.
- 27. VSS 2005에 파일을 체크인 할 때 참조가 누락되었습니다.
- 28. Subversion에 체크인 할 때 원본 파일 타임 스탬프를 유지하려면 어떻게해야합니까?
- 29. Foursquare - 친구 체크 인 기록?
- 30. 단일 플랫폼 및 Foursquare API
이미지 데이터를 전달해야하는 매개 변수를 알려주십시오. – Richa
사진이 매개 변수 중 하나에서 전달되지 않습니다. 이미지 데이터는 HTTP 요청에서 POST 메시지 본문으로 전송됩니다. HTTP 요청에 대한 자세한 내용은 http://en.wikipedia.org/wiki/HTTP_request#Request_message를 참조하십시오. – pfhayes
고맙습니다. 지원해 주셔서 대단히 감사합니다. – Richa