I am confused about publishing a post on facebook using C# sdk
I want to publish Name ,Description and photo on my page:
Do i need "publish_actions " in "items in review"(permissions)? because it is my own page .
When i try to add publish_actions ,facebook asks for privacy policy url ,How am i supposed to make it using C# Desktop Application, I didn't Found useful help on google.
Settings:
I have added http: //localhost:80/ to my site URL and:
http://abbasnaqvi512.tumblr.com/ to Valid OAuth redirect URIs.
Native or desktop app?=Yes
Is your App Secret embedded?=No
Client OAuth Login=yes
Embedded browser OAuth Login=NO
App Secret Proof for Server API calls=No
Require 2-factor reauthorization=No
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
try
{
if (e.Url.OriginalString.Contains("assets") && e.Url.OriginalString.Contains("code"))
{
code = Regex.Matches(e.Url.OriginalString, "assets.tumblr.com.*?code%3D(?<data>.*?)&")[0].Groups["data"].Value;
richTextBox1.Text += "\n\n" + code + "\n\n";
if (String.IsNullOrEmpty(code) == false)
{
webBrowser1.Stop();
webBrowser1.Dispose();
ShareOnFB();
}
}
}
catch (Exception)
{
}
}
private void ShareOnFB()
{
string pageId = "ABC";
FacebookClient client = new FacebookClient(code);
dynamic messagePost = new ExpandoObject();
messagePost.access_token = code;
messagePost.picture = "http://fc02.ostadreza-d6pkzrd.jpg";
// messagePost.link = "http://www.examplearticle.com";
messagePost.name = "NAME";
messagePost.description = "DESCRIPTION";
var result = client.Post(string.Format("/{0}/feed", pageId), messagePost);
richTextBox1.Text += "\n\n"+result+"\n\n";
}
Rightnow it is giving me Error
"Malformed access token AQA44CIJCyoV7_Xlz3mtvdPErPBrmtF6ykz6teCc9QINrfePHxEOiQKIyl8wgxH1mvQxEtLE-xnVfdyfiE38eA2M1YU7RS22MNIKNUh5wMmd2zwPCLj30PiEaq6CKIfcq9yIvq_slblOWmE4LYcynyH_pJuZcPc3EqLCQoCUBtSO58X1WtiohRoRvq70QWHpZec-7jhzUQnW75nlk4wpEwcJ9yOcBlPbne72sV6yX_hqndI5RKVDjqRJzdOscOblbLCkC1xtI0rMD1bCJufvpAa-tMsIyG6ATqrk6TNqXXASlcvialbzh0WttS2x-j_J59LF7cBh22T18P8qOly5cOwF"
Thanks for reading my question ,Kindly help me,
Update: I have added publish_actions in review by adding tumblr privacy policy url ,Notes and screen shots of my application ,It is on review
Related
I have a web application in asp.net . I want to use login with twiiter to get get user info. I have followed all instructions mentioned in below article
http://www.aspsnippets.com/Articles/Login-with-Twitter-in-ASPNet-using-Twitter-Button.aspx
I am getting redirected to twitter app then after authentication I am being redirected to my localhost app. Then I have check user is authorized but when I try to get user details by method FetchProfile() I am getting error.
My code is as below :
First on button click
protected void LoginTwitter(object sender, EventArgs e)
{
if (!TwitterConnect.IsAuthorized)
{
TwitterConnect twitter = new TwitterConnect();
twitter.Authorize(Request.Url.AbsoluteUri.Split('?')[0]);
}
}
then after authenticating back from twitter . on page load of application
I have check url its
http://localhost:63977/Account/Login?oauth_token=K0mECAAAAAAAxRXEAAABV44xPgc&oauth_verifier=qYLFiOlFPx4gxEu6V4AmTJG2JNjJ3nV2
then code to check
protected void Page_Load(object sender, EventArgs e)
{
TwitterConnect.API_Key = HelperClasses.TwitterApiKey;
TwitterConnect.API_Secret = HelperClasses.TwitterApiSecret;
if (Request.QueryString["oauth_token"] != null)
{
//twiiter
if (TwitterConnect.IsAuthorized)
{
TwitterConnect twitter = new TwitterConnect();
//LoggedIn User Twitter Profile Details
DataTable twitterUserDataTable = twitter.FetchProfile(); // error here
}
}
}
Tweetinvi provides a sample project doing exactly what you want to do : https://github.com/linvi/tweetinvi/tree/master/Examplinvi.Web.
I have highlighted the lines you will be interested in :
https://github.com/linvi/tweetinvi/blob/master/Examplinvi.Web/Controllers/HomeController.cs#L14-L36
You can also find more about the Authentication in tweetinvi here : https://github.com/linvi/tweetinvi/wiki/Authentication.
Here is the snippet that you want to use of ASP.NET authentication :
private IAuthenticationContext _authenticationContext;
// Step 1 : Redirect user to go on Twitter.com to authenticate
public ActionResult TwitterAuth()
{
var appCreds = new ConsumerCredentials("CONSUMER_KEY", "CONSUMER_SECRET");
// Specify the url you want the user to be redirected to
var redirectURL = "http://" + Request.Url.Authority + "/Home/ValidateTwitterAuth";
_authenticationContext = AuthFlow.InitAuthentication(appCreds, redirectURL);
return new RedirectResult(authenticationContext.AuthorizationURL);
}
public ActionResult ValidateTwitterAuth()
{
// Get some information back from the URL
var verifierCode = Request.Params.Get("oauth_verifier");
// Create the user credentials
var userCreds = AuthFlow.CreateCredentialsFromVerifierCode(verifierCode, _authenticationContext);
// Do whatever you want with the user now!
ViewBag.User = Tweetinvi.User.GetAuthenticatedUser(userCreds);
return View();
}
Not Able to login using .Net Web Application(C#) in Net Suite...
If Any One Have Solution please give me step by step
protected void btnLogin_Click(object sender, EventArgs e)
{
try
{
NetSuiteService service = new NetSuiteService();
service.CookieContainer = new CookieContainer();
//invoke the login operation
Passport passport = new Passport();
passport.account = "TSTDRV986543";
passport.email = txtUserName.Text;
passport.password = txtPassword.Text;
RecordRef role = new RecordRef();
role.internalId = "3";
passport.role = role;
Status status = service.login(passport).status;
}
}
I am using https://webservices.netsuite.com/wsdl/v2014_2_0/netsuite.wsdl This url to import web services and also I already change all URL type.
You should check out the SuiteTalk sample applications for sample requests to NetSuite, both in C# and in Java: http://www.netsuite.com/portal/developers/resources/suitetalk-sample-applications.shtml
It is also possible to troubleshoot the SOAP requests and responses by going in NetSuite, under Setup -> Integration -> Web Service Usage Logs.
I need to share a message on facebook from wp8. I attached my Main.xaml screenshot.
When click share button, first login to Facebook and then ask permission for the App. I used following code.
private FacebookSession session;
private async Task Authenticate()
{
string message = String.Empty;
try
{
session = await App.FacebookSessionClient.LoginAsync("user_about_me,publish_actions,read_stream");
App.AccessToken = session.AccessToken;
App.FacebookId = session.FacebookId;
Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/Share/LandingPage.xaml", UriKind.Relative)));
}
catch (InvalidOperationException e)
{
message = "Login failed! Exception details: " + e.Message;
MessageBox.Show(message);
}
}
And then in Loading method of LandingPage.xaml , used following code to publish message.
private async void LandingPage_Loaded(object sender, RoutedEventArgs e)
{
FacebookClient client = new FacebookClient(App.AccessToken);
var parameters = new Dictionary<string, object>();
parameters.Add("message", "First test post using Facebook login");
await client.PostTaskAsync("me/feed", parameters);
}
When I run the App , successfully login to the Facebook, but permission screen appear as follows.
clicked ok . And then an error is occurred.
(OAuthException - #200) (#200) The user hasn't authorized the application to perform this action
I tried to solve this issue my best , but I failed . If anybody has an idea to solve this. please help me
Thank You.
I Think you are missing the Request code from your access token request.
dynamic result = facebookClient.Get("oauth/access_token", new
{
client_id = appId,
client_secret = appSecret,
grant_type = "authorization_code"
redirect_uri = Request.Url.AbsoluteUri,
code = Request["code"]
});
I write a windows forms application that connects to user's profile in facebook, reads his wall and shows him updates in a widget, with the help of facebook c# sdk.
Everything works fine, except for the fact that facebook won't let my user change his credentials, that means re-login as a different user.
My authentication flow is schematically as follows:
In login process initializer:
note: The dialog is shown in a popup. If you show dialog in a full
browser, it's possible to logout, but in popup this functionality
seems to be lacking.
private void loginButton_Click(object sender, EventArgs e){
browser = new WebBrowser();
this.browser.Navigated += new WebBrowserNavigatedEventHandler(browser_Navigated);
//+ all types of gui settings for the borwser
form.Controls.Add(browser);
Uri url=new Uri("https://www.facebook.com/dialog/oauth?client_id=" + {*MyAppsId*}+
"&redirect_uri=" + "https://www.facebook.com/connect/login_success.html" +
"&response_type=token"+
"&auth_type=reauthenticate"+
"&display=popup"+
"&scope=read_stream"
browser.Navigate(url);// +try/catches - omitted
}
Navigation response parsing:
note: just parsing the response with the use of c# sdk classes FacebookOAuthResult and FacebookClient
private void browser_Navigated(object sender, WebBrowserNavigatedEventArgs e){
FacebookOAuthResult oauthResult; //helps to streamline parsing
if (fb.TryParseOAuthCallbackUrl(e.Url, out oauthResult)){ //type of fb is FacebookClient of c# sdk
if (oauthResult.IsSuccess){
accessToken = oauthResult.AccessToken;
//from here start reaing user's feed with the help of access token
}
}
}
What i meant to do by it is that when the login button is clicked, the user is prompted his username and password.
However, the user is prompted to re-enter his password only, not to re-enter his username.
If I use the url without the "&auth_type=reauthenticate" parameter , it doesn't prompt for anything and straight sends me the access token.
How can I force the facebook to ask for a username?
After days of fighting, the answer was under my nose.
You just need to call https://www.facebook.com/logout.php with your access token:
WebBrowser browser = new WebBrowser();
browser.Navigated += browser_NavigatedLogout;
string logoutUrl = "https://www.facebook.com/logout.php?" +
"next=https://www.facebook.com/connect/login_success.html" +
"&access_token=" + MyAccessToken;
try
{
browser.Navigate(new Uri(logoutUrl));
}
catch (System.Exception other)
{
MessageBox.Show("error logging out: "+other.Message);
}
and the handler is:
private void browser_NavigatedLogout(object sender, WebBrowserNavigatedEventArgs e)
{
if (e.Url.AbsoluteUri == "https://www.facebook.com/connect/login_success.html")
{
//here anything you need to do after the user logged off
}
}
I'm building an application for WP7 using the Facebook C# SDK. When I attempt to post a message to a users wall (Just a plain message) everything works fine. But when I attempt to post a link to the users wall I get this exception message:
(OAuthException) (#100) The post's links must direct to the application's connect or canvas URL.
Does anyone know how to fix this? I have heard of canvas applications but I didn't think this applied to a phone app. Perhaps this is a setting on Facebook?
Any feedback is appreciated.
Here is the code I used to post to facebook:
private void button1_Click(object sender, RoutedEventArgs e)
{
_fbClient.PostCompleted +=
(o, er) =>
{
if (er.Error == null)
{
MessageBox.Show("Success");
}
else
{
MessageBox.Show(er.Error.Message);
}
};
var args = new Dictionary<string, object>();
args["name"] = "Hello World!!";
args["link"] = "http://www.nfl.com";
args["caption"] = "";
args["description"] = "";
args["picture"] = "";
args["message"] = "Hello World from application.";
args["actions"] = "";
FacebookAsyncCallback callback = new FacebookAsyncCallback(this.postResult);
_fbClient.PostAsync("me/feed", args, callback);
}
private void postResult(FacebookAsyncResult asynchResult)
{
MessageBox.Show("Success");
}
NOTE: If I remove the string from "link" it works.
I found a solution to my problem "here". In your app settings within Facebook you have to set "Stream Post Url Security" to false. Hope this helps someone.
Go to the Facebook App. Edit its settings. On the Advanced settings page, disable the "Stream post URL security" option.