当前位置:  开发笔记 > 编程语言 > 正文

Facebook Connect Android - 使用stream.publish @ http://api.facebook.com/restserver.php

如何解决《FacebookConnectAndroid-使用stream.publish@http://api.facebook.com/restserver.php》经验,为你挑选了0个好方法。

我收到以下错误:

104
Incorrect signature

我应该将contentType类型设置为什么?我应该设置为:

String contentType = "application/x-www-form-urlencoded";

要么

String contentType = "multipart/form-data; boundary=" + kStringBoundary; 

这就是我写流的方式:

HttpURLConnection conn = null;
OutputStream out = null;
InputStream in = null;
try {
    conn = (HttpURLConnection) _loadingURL.openConnection();
    conn.setDoOutput(true);
    conn.setDoInput(true);
    if (method != null) {
        conn.setRequestMethod(method);
        if ("POST".equals(method)) {
            //"application/x-www-form-urlencoded";
            String contentType = "multipart/form-data; boundary=" + kStringBoundary;
            //String contentType = "application/x-www-form-urlencoded";
            conn.setRequestProperty("Content-Type", contentType);
        }

        // Cookies are used in FBPermissionDialog and FBFeedDialog to
        // retrieve logged user
       conn.connect();
       out = conn.getOutputStream();
       if ("POST".equals(method)) {
            String body = generatePostBody(postParams);
            if (body != null) {
                out.write(body.getBytes("UTF-8"));
            }
        }
        in = conn.getInputStream();

这是我用来发布流的方法:

private void publishFeed(String themessage) {
    //Intent intent = new Intent(this, FBFeedActivity.class);
   // intent.putExtra("userMessagePrompt", themessage);
  //  intent.putExtra("attachment", 
    Map getParams = new HashMap();
    // getParams.put("display", "touch");
    // getParams.put("callback", "fbconnect://success");
    // getParams.put("cancel", "fbconnect://cancel");

     Map postParams = new HashMap();

     postParams.put("api_key", _session.getApiKey());
     postParams.put("method", "stream.publish");
     postParams.put("session_key", _session.getSessionKey());
     postParams.put("user_message", "TESTING 123");
    // postParams.put("preview", "1");
     postParams.put("attachment", "{\"name\":\"Facebook Connect for Android\",\"href\":\"http://code.google.com/p/fbconnect-android/\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}");
    // postParams.put("user_message_prompt", "22222");


     try {
         loadURL("http://api.facebook.com/restserver.php", "POST", getParams, postParams);
     } catch (MalformedURLException e) {
         e.printStackTrace();
     }
}

这是generatePostBody():

private String generatePostBody(Map params) {
    StringBuilder body = new StringBuilder();
    StringBuilder endLine = new StringBuilder("\r\n--").append(kStringBoundary).append("\r\n");

    body.append("--").append(kStringBoundary).append("\r\n");

    for (Entry entry : params.entrySet()) {
        body.append("Content-Disposition: form-data; name=\"").append(entry.getKey()).append("\"\r\n\r\n");
        String value = entry.getValue();
        if ("user_message_prompt".equals(entry.getKey())) {
            body.append(value);
        }
        else {
            body.append(CcUtil.encode(value));
        }

        body.append(endLine);
    }

    return body.toString();
}

谢谢.

推荐阅读
小妖694_807
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有