Created
March 30, 2011 13:42
-
-
Save sankarganesh/894413 to your computer and use it in GitHub Desktop.
FB APP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is My code to publish checkin | |
public String APP_ID="101782413241377"; | |
Facebook authenticatedFacebook = new Facebook(APP_ID); | |
AsyncFacebookRunner fbinvoker=new AsyncFacebookRunner(authenticatedFacebook); | |
Bundle params = new Bundle(); | |
params.putByteArray("access_token",Main.access.getBytes()); | |
params.putByteArray("message", "Hi".getBytes()); | |
params.putByteArray("place", Main.place_id.getBytes()); | |
JSONObject jo = new JSONObject(); | |
JSONObject frnd_data=new JSONObject(); | |
try { | |
jo.put("latitude", lat_value); | |
jo.put("longitude", long_value); | |
params.putByteArray("coordinates", jo.toString().getBytes()); | |
frnd_data.put("USER_ID1", "100000838520166"); | |
params.putByteArray("tags", frnd_data.toString().getBytes()); | |
fbinvoker.request("https://graph.facebook.com/me/checkins", params, "POST",null,null); | |
} catch (JSONException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
this is that method | |
public static String openUrl(String url, String method, Bundle params) | |
throws MalformedURLException, IOException { | |
// random string as boundary for multi-part http post | |
String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"; | |
String endLine = "\r\n"; | |
OutputStream os; | |
if (method.equals("GET")) { | |
url = url + "?" + encodeUrl(params); | |
} | |
Log.d("Facebook-Util", method + " URL: " + url); | |
HttpURLConnection conn = | |
(HttpURLConnection) new URL(url).openConnection(); | |
conn.setRequestProperty("User-Agent", System.getProperties(). | |
getProperty("http.agent") + " FacebookAndroidSDK"); | |
if (!method.equals("GET")) { | |
Bundle dataparams = new Bundle(); | |
for (String key : params.keySet()) { | |
if (params.getByteArray(key) != null) { | |
dataparams.putByteArray(key, params.getByteArray(key)); | |
} | |
} | |
// use method override | |
if (!params.containsKey("method")) { | |
params.putString("method", method); | |
} | |
if (params.containsKey("access_token")) { | |
String decoded_token = | |
URLDecoder.decode(params.getString("access_token")); | |
params.putString("access_token", decoded_token); | |
} | |
conn.setRequestMethod("POST"); | |
conn.setRequestProperty( | |
"Content-Type", | |
"multipart/form-data;boundary="+strBoundary); | |
conn.setDoOutput(true); | |
conn.setDoInput(true); | |
conn.setRequestProperty("Connection", "Keep-Alive"); | |
conn.connect(); | |
os = new BufferedOutputStream(conn.getOutputStream()); | |
os.write(("--" + strBoundary +endLine).getBytes()); | |
os.write((encodePostBody(params, strBoundary)).getBytes()); | |
os.write((endLine + "--" + strBoundary + endLine).getBytes()); | |
if (!dataparams.isEmpty()) { | |
for (String key: dataparams.keySet()){ | |
os.write(("Content-Disposition: form-data; filename=\"" + key + "\"" + endLine).getBytes()); | |
os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes()); | |
os.write(dataparams.getByteArray(key)); | |
os.write((endLine + "--" + strBoundary + endLine).getBytes()); | |
} | |
} | |
os.flush(); | |
} | |
String response = ""; | |
try { | |
response = read(conn.getInputStream()); | |
} catch (FileNotFoundException e) { | |
// Error Stream contains JSON that we can parse to a FB error | |
response = read(conn.getErrorStream()); | |
} | |
return response; | |
} | |
this is the format i had reffered from facebook sdk | |
curl -F 'access_token=...' \ | |
-F 'message=The coffee is just meh.' \ | |
-F 'place=PAGE_ID' \ | |
-F 'coordinates={"latitude":"...", "longitude": "..."}' \ | |
-F 'tags=USER_ID1, USER_ID2' \ | |
https://graph.facebook.com/me/checkins | |
Now i m getting these error | |
03-30 19:50:23.621: WARN/Bundle(13255): Key format expected byte[] but value was a java.lang.String. The default value <null> was returned. | |
03-30 19:50:23.651: WARN/Bundle(13255): Attempt to cast generated internal exception: | |
03-30 19:50:23.651: WARN/Bundle(13255): java.lang.ClassCastException: java.lang.String | |
03-30 19:50:23.651: WARN/Bundle(13255): at android.os.Bundle.getByteArray(Bundle.java:1220) | |
03-30 19:50:23.651: WARN/Bundle(13255): at com.facebook.android.Util.openUrl(Util.java:155) | |
03-30 19:50:23.651: WARN/Bundle(13255): at com.facebook.android.Facebook.request(Facebook.java:559) | |
03-30 19:50:23.651: WARN/Bundle(13255): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253) | |
03-30 22:55:48.911: DEBUG/Facebook-Util(18288): POST URL: https://graph.facebook.com/https://graph.facebook.com/me/checkins | |
03-30 22:55:48.931: WARN/Bundle(18288): Key format expected byte[] but value was a java.lang.String. The default value <null> was returned. | |
03-30 22:55:48.951: WARN/Bundle(18288): Attempt to cast generated internal exception: | |
03-30 22:55:48.951: WARN/Bundle(18288): java.lang.ClassCastException: java.lang.String | |
03-30 22:55:48.951: WARN/Bundle(18288): at android.os.Bundle.getByteArray(Bundle.java:1220) | |
03-30 22:55:48.951: WARN/Bundle(18288): at com.facebook.android.Util.openUrl(Util.java:155) | |
03-30 22:55:48.951: WARN/Bundle(18288): at com.facebook.android.Facebook.request(Facebook.java:559) | |
03-30 22:55:48.951: WARN/Bundle(18288): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:255) | |
03-30 22:55:48.961: WARN/Bundle(18288): Key access_token expected String but value was a [B. The default value <null> was returned. | |
03-30 18:52:07.0703-30 18:52:07.071: WARN/Bundle(11412): at android.os.Handler.dispatchMessage(Handler.java:99) | |
03-30 18:52:07.071: WARN/Bundle(11412): at android.os.Looper.loop(Looper.java:123) | |
03-30 18:52:07.071: WARN/Bundle(11412): at android.app.ActivityThread.main(ActivityThread.java:4203) | |
03-30 18:52:07.071: WARN/Bundle(11412): at java.lang.reflect.Method.invokeNative(Native Method) | |
03-30 18:52:07.071: WARN/Bundle(11412): at java.lang.reflect.Method.invoke(Method.java:521) | |
03-30 18:52:07.071: WARN/Bundle(11412): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) | |
03-30 18:52:07.071: WARN/Bundle(11412): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) | |
03-30 18:52:07.071: WARN/Bundle(11412): at dalvik.system.NativeStart.main(Native Method) | |
03-30 18:52:07.081: WARN/dalvikvm(11412): threadid=3: thread exiting with uncaught exception (group=0x4001da28) | |
03-30 18:52:07.081: ERROR/AndroidRuntime(11412): Uncaught handler: thread main exiting due to uncaught exception | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): java.lang.NullPointerException | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at org.apache.harmony.luni.util.Util.decode(Util.java:247) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at java.net.URLDecoder.decode(URLDecoder.java:52) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at com.facebook.android.Util.openUrl(Util.java:167) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at com.facebook.android.Facebook.request(Facebook.java:559) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at com.checkins.demo.FBMapActivity$1.onClick(FBMapActivity.java:118) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.view.View.performClick(View.java:2344) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.view.View.onTouchEvent(View.java:4133) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.widget.TextView.onTouchEvent(TextView.java:6504) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.view.View.dispatchTouchEvent(View.java:3672) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.app.Activity.dispatchTouchEvent(Activity.java:1987) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.view.ViewRoot.handleMessage(ViewRoot.java:1658) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.os.Handler.dispatchMessage(Handler.java:99) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.os.Looper.loop(Looper.java:123) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at android.app.ActivityThread.main(ActivityThread.java:4203) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at java.lang.reflect.Method.invokeNative(Native Method) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at java.lang.reflect.Method.invoke(Method.java:521) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) | |
03-30 18:52:07.121: ERROR/AndroidRuntime(11412): at dalvik.system.NativeStart.main(Native Method) | |
03-30 18:52:07.141: INFO/Process(73): Sending signal. PID: 11412 SIG: 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment