I am extending social media integration onto an app.
Found this post but no suitable answer.
In a nutshell:
Post photo onto user1's wall (after they have logged in).
"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.
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.
Comments