Sharing or linking post using Facebook Graph API on windows forms app

EaziLuizi

I am extending social media integration onto an app.

Found this post but no suitable answer.

In a nutshell:

  1. Post photo onto user1's wall (after they have logged in).

  2. "Share" the post user2's wall (after they have logged in).

I need to be able to login and upload photos to the account that I am currently logged in with.(I have achieved this).

I think this is the logic required:

Retrieve the post_id and share/post it onto another users timeline... I have got it all working up to and including retrieving the post_id. Now I am stuck and I can't seem to find a solution, maybe its just been a long week...

It is a windows forms app (don't judge - not my call) and I generate login using this code:

    public static string GenerateLoginUrl()
    {
        dynamic parameters = new ExpandoObject();
        parameters.client_id = ""; //app id
        parameters.redirect_uri = "https://www.google.com"; 
        parameters.response_type = "token";
        parameters.display = "popup";

        var fb = new FacebookClient();
        Uri loginUri = fb.GetLoginUrl(parameters);
        return loginUri.AbsoluteUri;
    }    

Which I then Validate after Navigating to the above URL using this:

    private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
    {
        if (webBrowser1.Visible)
        {
            var fb = new FacebookClient();
            FacebookOAuthResult oauthResult;
            if (fb.TryParseOAuthCallbackUrl(e.Url, out oauthResult))
            {
                if (oauthResult.IsSuccess)
                {
                    //happy
                }
            }
        }
    }

I retrieve post_id on the "PostCompleted" method of the FacebookClient class instance as follows:

 fb.PostCompleted += (oo, eee) =>
    {
        if (eee.Cancelled || eee.Error != null)
        {
            return;
        }
        var result = eee.GetResultData();
        JsonObject myObj = (JsonObject)result;
        string post_id = myObj["post_id"].ToString();
    };

I have managed to do all the little bits and pieces, but now I am stuck on bringing it together, thank you in advance, any information and helpful links would be great please.

EaziLuizi

Finally got it working to meet my requirements...

NOTE: This answer assumes you understand the basics of authenticating and posting using the C# Facebook API:

fb.PostCompleted += (o, ee) =>
    {
        if (ee.Cancelled || ee.Error != null)
            return;

        JsonObject myObj = (JsonObject)ee.GetResultData();
        string href = String.Format("https://www.facebook.com/photo.php?fbid={0}&set=a.{1}", myObj["id"].ToString(), myObj["post_id"].ToString());

        this.Invoke(new MethodInvoker(delegate()
        {
            ClientLogin loginDialog = new ClientLogin(href);
            loginDialog.Show();
        }));
    };
fb.PostTaskAsync(parameters);

Once the task completes, I open a form that contains a "WebBrowser" control where I call the following code:

webBrowserOAuth.Navigate(String.Format(@"https://www.facebook.com/dialog/feed?app_id={0}&href={1}&redirect_uri={2}", app_id, _href, redirect_uri));

Then handle the "webBrowserOAuth_Navigated" event to meet your requirements...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Facebook sharing video Graph API

From Dev

How to post a video using Facebook Graph API

From Dev

Post photo on Facebook group using graph api

From Dev

Post Image to the Facebook using Graph API

From Dev

Post Image to the Facebook using Graph API

From Dev

Post photo on Facebook group using graph api

From Dev

Post in feeds with Link Facebook Graph API (Titanium Studio app)

From Dev

Sharing audio on facebook using open graph

From Dev

Facebook Graph API Post with a place

From Dev

Post message with picture to facebook page/feed using graph api

From Dev

How to delete post in facebook by id using php, graph API

From Dev

Facebook Post Call to Action button using Graph API

From Dev

Python how to do facebook wall post using graph api?

From Dev

Facebook Post Call to Action button using Graph API

From Dev

How to verify if published post using Facebook Graph API is set to public

From Dev

Get app activity log using graph-facebook-api

From Dev

Facebook Graph API and app secret

From Dev

Using Facebook graph Api in c# windows application

From Dev

In Android Shared post from my app using Facebook sharing dialog is showing to me but not to others . Why?

From Dev

Trying to post message to facebook using windows client app

From Dev

How can identify Facebook post is already liked or not using Facebook graph API?

From Dev

Post Picture Facebook - Graph API - PHP

From Dev

Facebook graph api. App notifications: A client gets notification, but server gets error in the response: Unsupported post request

From Dev

Query app pictures through Facebook graph api

From Dev

Facebook Graph API: Find graph object from post URL

From Dev

How to count likes/comments of a photo/post using new Facebook Graph API 2.1?

From Dev

Facebook post to fan page using php sdk5 graph api 2.4

From Dev

Using the Facebook Graph API, can you detect if a Page Post is boosted / sponsored / suggested?

From Dev

Facebook post to fan page using php sdk5 graph api 2.4

Related Related

  1. 1

    Facebook sharing video Graph API

  2. 2

    How to post a video using Facebook Graph API

  3. 3

    Post photo on Facebook group using graph api

  4. 4

    Post Image to the Facebook using Graph API

  5. 5

    Post Image to the Facebook using Graph API

  6. 6

    Post photo on Facebook group using graph api

  7. 7

    Post in feeds with Link Facebook Graph API (Titanium Studio app)

  8. 8

    Sharing audio on facebook using open graph

  9. 9

    Facebook Graph API Post with a place

  10. 10

    Post message with picture to facebook page/feed using graph api

  11. 11

    How to delete post in facebook by id using php, graph API

  12. 12

    Facebook Post Call to Action button using Graph API

  13. 13

    Python how to do facebook wall post using graph api?

  14. 14

    Facebook Post Call to Action button using Graph API

  15. 15

    How to verify if published post using Facebook Graph API is set to public

  16. 16

    Get app activity log using graph-facebook-api

  17. 17

    Facebook Graph API and app secret

  18. 18

    Using Facebook graph Api in c# windows application

  19. 19

    In Android Shared post from my app using Facebook sharing dialog is showing to me but not to others . Why?

  20. 20

    Trying to post message to facebook using windows client app

  21. 21

    How can identify Facebook post is already liked or not using Facebook graph API?

  22. 22

    Post Picture Facebook - Graph API - PHP

  23. 23

    Facebook graph api. App notifications: A client gets notification, but server gets error in the response: Unsupported post request

  24. 24

    Query app pictures through Facebook graph api

  25. 25

    Facebook Graph API: Find graph object from post URL

  26. 26

    How to count likes/comments of a photo/post using new Facebook Graph API 2.1?

  27. 27

    Facebook post to fan page using php sdk5 graph api 2.4

  28. 28

    Using the Facebook Graph API, can you detect if a Page Post is boosted / sponsored / suggested?

  29. 29

    Facebook post to fan page using php sdk5 graph api 2.4

HotTag

Archive