trying to upload video using graph api -


i have been trying implement video upload facebook feature mobile app while never succeeded rest. learnt yesterday graph alternative available.

after getting few errors access key have gotten point output stream succesfully writes movie file , input stream receives empty json array once have written 3gp file.

anyone idea why empty json array , no video gets published when code run, 200 response code , server sends me non error response?

any appreciated.

here class gets blank json array (send method). have appended token url , in table sure. sorry if code untidy buts been day of trial , error.

import java.io.bytearrayoutputstream; import java.io.inputstream; import java.io.outputstream; import java.util.enumeration; import java.util.hashtable; import javax.microedition.io.connector; import javax.microedition.io.httpconnection; import net.rim.device.api.io.http.httpprotocolconstants;

public class httpmultipartrequest2 { static final string boundary = "----------v2ymhfg03ehbqgzcako6jy"; byte[] postbytes = null; string url = null; hashtable paramstable;

public httpmultipartrequest2(string url, hashtable params,         string filefield, string filename, string filetype, byte[] filebytes) throws exception {     this.url = url;      string boundary = getboundarystring();     paramstable = params;     string boundarymessage = getboundarymessage(boundary, params, filefield, filename, filetype);     string endboundary = "\r\n--" + boundary + "--\r\n";     bytearrayoutputstream bos = new bytearrayoutputstream();     bos.write(boundarymessage.getbytes());     bos.write(filebytes);     bos.write(endboundary.getbytes());     this.postbytes = bos.tobytearray();     bos.close(); } string getboundarystring()  {     return boundary; }  string getboundarymessage(string boundary, hashtable params, string filefield, string filename, string filetype) {     stringbuffer res = new stringbuffer("--").append(boundary).append("\r\n");     enumeration keys = params.keys();     while(keys.hasmoreelements())     {         string key = (string)keys.nextelement();         string value = (string)params.get(key);         res.append("content-disposition: form-data; name=\"").append(key).append("\"\r\n")                 .append("\r\n").append(value).append("\r\n")                 .append("--").append(boundary).append("\r\n");     }     res.append("content-disposition: form-data; name=\"").append(filefield)             .append("\"; filename=\"").append(filename).append("\"\r\n")             .append("content-type: ").append(filetype).append("\r\n\r\n");     log.info(("res "+res.tostring()));     return res.tostring(); }  public string send() throws exception {     stringbuffer sb = new stringbuffer();     httpconnection hc = null;     inputstream = null;     bytearrayoutputstream bos = new bytearrayoutputstream();     byte[] res = null;     try     {         log.info("before hc open"+ url);         hc = (httpconnection) connector.open(url);         hc.setrequestproperty("content-type", "multipart/form-data; boundary=" + getboundarystring());         hc.setrequestproperty("access_token", (string)paramstable.get("access_token"));         hc.setrequestproperty(httpprotocolconstants.header_content_length, string.valueof(postbytes.length));         hc.setrequestproperty( "x-rim-transcode-content", "none" );         bytearrayoutputstream out = new bytearrayoutputstream();         outputstream dos = hc.openoutputstream();          = hc.openinputstream();            log.info("before  dos write responsecode");// + hc.getresponsecode());         out.write(postbytes, 0, postbytes.length);          //log.info("flushing"+ hc.getresponsecode());         log.info("after  doswrite responsecode");                dos.write(out.tobytearray());                dos.flush();                      log.info("after flush");                     if(dos!=null)                             dos.close();         int ch;          log.info("before openinput ");             log.info("after openinput ");         while ((ch = is.read()) != -1)         {             bos.write(ch);             sb.append((char)ch);                log.info("char"+(char)ch);         }         res = bos.tobytearray();           log.info("response recieved server : " + sb.tostring() );      }     catch(exception e)     {         log.info(hc.getresponsecode() + "sexce"+e);     }     catch(outofmemoryerror error)             {                     log.info("outofmemory " + error);                   system.gc();             }         {         try         {             if(bos != null)                 bos.close();             if(is != null)                 is.close();             if(hc != null)                 hc.close();         }         catch(exception e2)         {            log.info("finally exception"+ e2);         }     }     return sb.tostring(); } 

}

are trying upload user's feed or page? there open bug regarding posting pages.

also, post code?

assuming you've read documentation:

facebook graph api->video

and using graph-video.facebook.com, not graph.facebook.com.


Comments