Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7906211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:49:51+00:00 2026-06-03T10:49:51+00:00

I’m trying to post a photo to Facebook using Graph API. I have managed

  • 0

I’m trying to post a photo to Facebook using Graph API. I have managed to post a message to my timeline, but not a photo. The Facebook-debugger gives no errors and the object properties are correct.

public class oAuthFacebook
{
    public enum Method { GET, POST };

    public const string AUTHORIZE = "https://graph.facebook.com/oauth/authorize";

    public const string ACCESS_TOKEN = "https://graph.facebook.com/oauth/access_token";

    public const string CALLBACK_URL ="http://test.com/FbCallback.aspx";


    private string _consumerKey = "";

    private string _consumerSecret = "";

    private string _token = "";



 public string ConsumerKey
{

    get
    {
        if (_consumerKey.Length == 0)
        {
            _consumerKey = "";
        }
        return _consumerKey;
    }
    set { _consumerKey = value; }
}


public string ConsumerSecret 
{
    get
    {
        if (_consumerSecret.Length == 0)
        {
            _consumerSecret = "";
        }
        return _consumerSecret;
    }
    set { _consumerSecret = value; }

    }

public string Token { get { return _token; } set { _token = value; } }





public string AuthorizationLinkGet()
{
    return string.Format("{0}?client_id={1}&redirect_uri={2}&,publish_actions",
  AUTHORIZE, this.ConsumerKey, CALLBACK_URL);
}

public void AccessTokenGet(string authToken)
{
    this.Token = authToken;
    string accessTokenUrl = string.Format("{0}?client_id={1}&redirect_uri=
  {2}&client_secret={3}&code={4}",
    ACCESS_TOKEN, this.ConsumerKey, CALLBACK_URL, this.ConsumerSecret, authToken);

    string response = WebRequest(Method.GET, accessTokenUrl, String.Empty);

    if (response.Length > 0)
    {
        NameValueCollection qs = HttpUtility.ParseQueryString(response);

        if (qs["access_token"] != null)
        {
            this.Token = qs["access_token"];
        }
    }
}

public string WebRequest(Method method, string url, string postData)
{
    HttpWebRequest webRequest = null;
    StreamWriter requestWriter = null;
    string responseData = "";
    webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
    webRequest.Method = method.ToString();
    webRequest.ServicePoint.Expect100Continue = false;
    webRequest.UserAgent = "http://test.com";
    webRequest.Timeout = 40000;

    if (method == Method.POST)
    {
        webRequest.ContentType = "application/x-www-form-urlencoded";

        requestWriter = new StreamWriter(webRequest.GetRequestStream());
        try
        {
            requestWriter.Write(postData);
        }
        catch
        {
            throw;
        }
        finally
        {
            requestWriter.Close();
            requestWriter = null;
        }
    }
    responseData = WebResponseGet(webRequest);
    webRequest = null;
    return responseData;
}



public string WebResponseGet(HttpWebRequest webRequest)
{
    StreamReader responseReader = null;
    string responseData = "";
    try
    {
        responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
        responseData = responseReader.ReadToEnd();
    }
    catch
    {
        throw;
    }
    finally
    {
        webRequest.GetResponse().GetResponseStream().Close();
        responseReader.Close();
        responseReader = null;
    }
    return responseData;
}

And this is how I sent a testmessage, it works fine:

var json = oAuth.WebRequest(oAuthFacebook.Method.POST, url, "message=" +
HttpUtility.UrlEncode("Testmessage"));

I’ve tried for days to get it to work with a photo instead, any ideas of what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:50:05+00:00Added an answer on June 3, 2026 at 10:50 am

    I can suggest to look at FB C# SDK (available here or in NuGet) instead of sending raw requests. Here is my function I use to upload images to FB album (you should either know album ID or you can create it as well, or you can enumerate all the albums and get the one you need):

    public static string UploadPhoto(string imageName, string albumID, string accesstoken, string photoComment = null, bool doNotPostStory = false)
    {
        var fbAPI = new FacebookApp(accesstoken);
        var p = new FacebookMediaObject {FileName = path};
    
        p.SetValue( <<YOUR IMAGE GOES HERE AS byte[]>>);
    
        p.ContentType = "multipart/form-data";
    
        var param = new Dictionary<string, object> { {"attachment", p} };
        if (!string.IsNullOrEmpty(photoComment))
            param.Add("message", photoComment);
    
        // http://stackoverflow.com/questions/7340949/is-it-possible-to-upload-a-photo-to-fanpage-album-without-publishing-it
        // http://developers.facebook.com/blog/post/482/
        if (doNotPostStory == true)
        {
            param.Add("no_story", "1");
        }
    
        var result = fbAPI.Post(string.Format("http://graph.facebook.com/{0}/photos", albumID), param);
        return result.ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.