2011-09-09 11 views
0

私はユーザーのFacebookの壁に公開しようとしています。私はC#でasp.netでそれを行う必要があります。誰かが働いているプロジェクトはありますか?必要なステップヘルプ。私はいくつかのプロジェクトを成功させました。私が試みている現在のプロジェクトは、最初の投稿の後に400の悪いリクエストエラーを返します。 だから、私は繰り返し、私は「私は誰もがASPまたはC#のためのFacebookのAPIを書いたかどうかを知ることができますが、ないエラーではなく、ウェブサイトの名前を返さない作業プロジェクト、 おかげで、 エイドリアンユーザーFacebookの壁にどのように公開できますか?

答えて

1

質問者(transportinoradea): まあ、最後に私はFacebookRequestとCallRequest<の代わりに別のメソッドを使って400エラーを出しました。今私はそれを処理し、すべてが大丈夫です。

/// <summary> 
/// 
/// </summary> 
/// <param name="accessToken"></param> 
/// <param name="message"></param> 
/// <param name="link"></param> 
/// <param name="picture"></param> 
/// <param name="title"></param> 
/// <param name="linkCaption"></param> 
/// <param name="description"></param> 
/// <returns> Will return empty string if is ok, else will return error message</returns> 
public string PublishToFbWall(String accessToken, String message, String link, String picture, String title, String linkCaption, String description) 
{ 
    String postData = ""; 
    if (accessToken == "") 
     return "Access token empty."; 

    postData += "access_token=" + accessToken; 

    if (message != "") 
     postData += "&message=" + message; 

    if (link != "") 
     postData += "&link=" + link; 

    if (picture != "") 
     postData += "&picture=" + picture; 

    if (title != "") 
     postData += "&title=" + title; 

    if (linkCaption != "") 
     postData += "&linkCaption=" + linkCaption; 

    if (description != "") 
     postData += "&description=" + description; 

    //postData += "&link=" + "http://www.transportinoradea.ro/"; 
    //postData += "&picture=" + "http://www.transportinoradea.ro/images/logo_transportinoradea_240_100.png"; 
    //postData += "&name=" + "tttt"; 
    //postData += "&caption=" + "linkCaption"; 
    //postData += "&description=" + "description as ds"; 

    return DoFacebookWebrequest(postData, "https://graph.facebook.com/me/feed"); 
} 

/// <summary> 
/// Prepare web request... 
/// </summary> 
/// <param name="postData"></param> 
/// <param name="url"></param> 
/// <returns> Will return empty string if is ok, else will return error message</returns> 
//private string DoFacebookWebrequest(String postData, String url, string accessToken, string message) 
private string DoFacebookWebrequest(String postData, String url) 
{ 
    try 
    { 
     WebClient wcc = null; 
     try 
     { 
      wcc = new WebClient(); 
      wcc.UploadString("https://graph.facebook.com/me/feed", null, postData); 
     } 
     catch (System.Net.WebException ex) 
     { 
      StreamReader readStream = new StreamReader(ex.Response.GetResponseStream()); 
      //This way wee can see the error message from facebook 
      string ErrorMessageJson = readStream.ReadToEnd(); 

      JavaScriptSerializer ser = new JavaScriptSerializer(); 

      ErrorFacebook facebookError = ser.Deserialize<ErrorFacebook>(ErrorMessageJson); 

      //throw new Exception(

      return "Error:" + " type(" + facebookError.error.type + "), message:" + facebookError.error.message + " "; 
      //); 

     } 

    } 
    catch (Exception e) 
    { 
     return e.Message; 
     //throw new Exception(e.ToString()); 
    } 
    return ""; 
} 
0

が必要基本的なHTTPリクエストでそれを行うだけですか?

http://developers.facebook.com/docs/reference/api/から:

「あなたはアクセストークンを使用して、適切な接続URLにHTTP POSTリクエストを発行することによって、Facebookのグラフを公開することができます。」

0

を私はあなたが既製のプロジェクトを取得することはできません怖いですそれを達成する方法を説明するサンプルです。

私はあなたがthisリンクを確認することを提案します、それはあなたが始めに役立ちます。

関連する問題