Hi ,
I have been working on this application to share a video/image on facebook
on my wall and googled a code and modified this a bit.Here is the code :
public class PicShareActivity extends Activity {
private static final String FB_APP_ID = "My=app-id-taken from facebook
after registering my application";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Inside the
FbookShareActivity");
setContentView(R.layout.main);
byte[] data = null;
String dataPath = "/data/digitechvideos/out.mpeg";
String dataMsg = "Test Video Sent form Nexus S.";
String dataName = ".mpeg";
Bundle param;
Facebook facebook = new Facebook(FB_APP_ID);
AsyncFacebookRunner mAsyncRunner = new
AsyncFacebookRunner(facebook);
InputStream is = null;
try {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Inside TRY
Block>>>>>>>>>>>>>>>>>>");
is = new FileInputStream(dataPath);
data = readBytes(is);
param = new Bundle();
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Before param
>>>>>>>>>>>>>>>>>>");
param.putString("message", dataMsg);
param.putString("filename", dataName );
param.putByteArray("video", data);
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Before
mAsyncRunner.request >>>>>>>>>>>>>>>>>>");
mAsyncRunner.request("https://www.facebook.com/<my-facebook-profile-id>/photos",
param, "POST",new fbRequestListener(), null);
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>After
mAsyncRunner.request >>>>>>>>>>>>>>>>>>");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public byte[] readBytes(InputStream inputStream) throws IOException {
// This dynamically extends to take the bytes you read.
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
// This is storage overwritten on each iteration with bytes.
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
// We need to know how may bytes were read to write them to the
// byteBuffer.
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
// And then we can return your byte array.
return byteBuffer.toByteArray();
}
But I am getting this error :
W/Bundle ( 865): Key message expected byte[] but value was a
java.lang.String. The default value <null> was returned.
W/Bundle ( 865): Attempt to cast generated internal exception:
W/Bundle ( 865): java.lang.ClassCastException: java.lang.String
W/Bundle ( 865): at android.os.Bundle.getByteArray(Bundle.java:1305)
W/Bundle ( 865): at com.facebook.android.Util.openUrl(Util.java:172)
W/Bundle ( 865): at
com.facebook.android.Facebook.request(Facebook.java:751)
W/Bundle ( 865): at
com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
W/Bundle ( 865): Key format expected byte[] but value was a
java.lang.String. The default value <null> was returned.
W/Bundle ( 865): Attempt to cast generated internal exception:
W/Bundle ( 865): java.lang.ClassCastException: java.lang.String
W/Bundle ( 865): at android.os.Bundle.getByteArray(Bundle.java:1305)
W/Bundle ( 865): at com.facebook.android.Util.openUrl(Util.java:172)
W/Bundle ( 865): at
com.facebook.android.Facebook.request(Facebook.java:751)
W/Bundle ( 865): at
com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
I suspect that the *authentication* is not happening also I am missing
something in the *fbRequestListener()* implementation.Can some one plz
point out what is wrong or any other sample code if at all it is possible
to share the images and videos from the gallery on the facebook's own wall.
here is the
reference<http://facebook.stackoverflow.com/questions/6908413/is-uploading-videos-from-an-sd-card-to-facebook-possible-with-the-facebook-sdk/9835145#9835145>
.
Rgds,
Saurabh
"..pain is temporary.....quitting lasts forever......"
--
You received this message because you are subscribed to the Google Groups
"Android Discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/android-discuss?hl=en.