android - Facebook wall post with text and image -
i've been stuck days looking simple tutorial on making facebook wall post icon or image , text using graph api. i've tried countless tutorials , seem complicated , can't them work. samples come sdk not create sessions.
i have been sucessful in setting sdk , getting app_id left java code custom button share app on users wall.
you can post image text application in way.
call method while clicking on button widget btnimageposttowall
like...
btnimageposttowall.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { postimagetowall(); } });
get profile information making request facebook graph api....
public void postimagetowall() { facebook.authorize( this, new string[] { "user_photos,publish_checkins,publish_actions,publish_stream" }, new dialoglistener() { @override public void onfacebookerror(facebookerror e) { // todo auto-generated method stub } @override public void onerror(dialogerror dialogerror) { // todo auto-generated method stub } @override public void oncomplete(bundle values) { postimageonwall(); } @override public void oncancel() { // todo auto-generated method stub } }); } private void postimageonwall() { byte[] data = null; bitmap bi = bitmapfactory.decoderesource(getresources(), r.drawable.ic_launcher); bytearrayoutputstream baos = new bytearrayoutputstream(); bi.compress(bitmap.compressformat.jpeg, 100, baos); data = baos.tobytearray(); bundle params = new bundle(); params.putstring(facebook.token, facebook.getaccesstoken()); params.putstring("method", "photos.upload"); params.putbytearray("picture", data); // image post params.putstring("caption", "my text on wall image "); // text post asyncfacebookrunner masyncrunner = new asyncfacebookrunner(facebook); masyncrunner.request(null, params, "post", new sampleuploadlistener(), null); }
just create class sampleuploadlistener implements asyncfacebookrunner.requestlistener...
class sampleuploadlistener implements asyncfacebookrunner.requestlistener { @override public void oncomplete(string response, object state) { } @override public void onioexception(ioexception e, object state) { } @override public void onfilenotfoundexception(filenotfoundexception e, object state) { } @override public void onmalformedurlexception(malformedurlexception e, object state) { } @override public void onfacebookerror(facebookerror e, object state) { } }
hope bit.... :-)
Comments
Post a Comment