Did Facebook change completely change their SDK? - c#

I've had a working application that connects and registers my users through their Facebook Accounts and retrieves some public information. Anyway, the application stopped working with Facebook with the new update (V2.6). I haven't changed any of my code, and now it's failing at creating a login URL for Facebook.
Last time I managed to Login successfully was on the 10th of April. I've read the Changelog for V2.6 but couldn't find anything that would/should change the Login flow. Here is the function that used to generate the Login URL and I would just get asked if I'd allow "my app" to access my Facebook information, I'd press allow and everything would continue perfectly. Now, I get the "SECURITY WARNING: Please treat the URL above as you would your password and do not share it with anyone. See the Facebook Help Centre for more information" error when the generated Login URL is called...
private string GenerateLoginUrlFacebook()
{
dynamic parameters = new ExpandoObject();
parameters.client_id = Globals.FBapplicationID;
parameters.redirect_uri = "https://www.facebook.com/connect/login_success.html";
parameters.response_type = "token";
parameters.display = "popup";
if (!string.IsNullOrWhiteSpace(Globals.FBextendedPermissionsNeeded))
parameters.scope = Globals.FBextendedPermissionsNeeded;
var fb = new FacebookClient();
Uri loginUri = fb.GetLoginUrl(parameters);
return loginUri.AbsoluteUri;
//return #"https://www.facebook.com/dialog/oauth?client_id=471150563090234&redirect_uri=https://www.facebook.com/connect/login_success.html";
}
Any help would be greatly appreciated!

Related

accessing facebook private messages using access token using Facebook API

We have angularJs & C# web aplication.
We are planning to use our facebook page to handle our customer issues and complaints.
We will show facebook visitor posts in our website so our representative notice it and reply on same. (may be new comment or reply existing)
Our representative ask customer to send private message and then user initiate message to us and then we can see that message in our website and reply to that message through our website.
By this way we will able to sort out problems of our customer through our application.
public static FacebookClient GetClientApplicationAccessToken(FacebookClient client)
{
dynamic accessToken = client.Get("oauth/access_token", new
{
client_id = "my_ApplicationId",
client_secret = "my_AppSecretKey",
grant_type = "client_credentials"
});
client.AccessToken = accessToken.access_token;
return client;
}
public static dynamic GetFacebookPosts(string pageId)
{
var client = new FacebookClient();
GetClientApplicationAccessToken(client);
dynamic postObject = client.Get("/" + pageId + "/feed?fields=message,from,created_time,full_picture");
dynamic postJson = JsonConvert.DeserializeObject(posts);
return postJson;
}
By this access token we are able to fetch Facebook post, but not possible when we try to fetch conversation between Our Facebook page & our customers through private messages.
dynamic postdaObject = newclient.Get("me?fields=conversations{messages{created_time,message}}");
I think when we use access token from above method i.e.GetClientApplicationAccessToken() it is not working. but if I replace hard coded user access token then it's working. As our application end user will see Facebook messages and will reply to them, it does not require FaceBook Login button. We need some permanent access token by which we can fetch private messages from Facebook without any login button. Kindly help me to solve this issue.

Facebook's OAuth "Given URL is not permitted by the Application configuration"

I was working on this program that connects my users through their Facebook accounts. It's been working quiet stable for the past couple of weeks, and I was able to add more value to my program during that period. However, starting today I was unable to connect through Facebook as I usually do. Whenever I ask for App authorization (1st step) I get a "Given URL is not permitted by the Application configuration" error, Even tho i didn't change anything in my App Settings.
I looked everywhere to check if maybe Facebook did some Updates or something, but couldn't find anything. Last time i logged in successfully was the 30th of March.
How could have this happened if I didn't edit any of my code, and apparently Facebook didn't either! Any help would be greatly appreciated :)
private string GenerateLoginUrlFacebook()
{
dynamic parameters = new ExpandoObject();
parameters.client_id = Globals.FBapplicationID;
parameters.redirect_uri = "https://www.facebook.com/connect/login_success.html";
parameters.response_type = "token";
parameters.display = "popup";
if (!string.IsNullOrWhiteSpace(Globals.FBextendedPermissionsNeeded))
parameters.scope = Globals.FBextendedPermissionsNeeded;
var fb = new FacebookClient();
Uri loginUri = fb.GetLoginUrl(parameters);
return loginUri.AbsoluteUri;
}

Facebook : No permission to publish the video

I am trying to upload video using c# facebook graph api, and its working fine for user development account, i am able to post on wall, but when i try to other user i am getting error :
(OAuthException - #100) (#100) No permission to publish the video
This is my sample code
**var fb = new Facebook.FacebookClient(token);
dynamic parameters = new ExpandoObject();
parameters.source = new Facebook.FacebookMediaObject { ContentType = "video/mp4", FileName = "video.mp4" }.SetValue(File.ReadAllBytes(#"D:\home\site\wwwroot\\Videos\abc.mp4"));
parameters.title = "test title";
parameters.description = "test description";
dynamic result = fb.Post("/me/videos", parameters);**
where i set the permission
**scope=publish_actions**
Please help me, Thank you in Advance.
In order to make publish_actions work for other users without a role in the App, you need to go through Login Review. Everything you need to know about that is in the docs: https://developers.facebook.com/docs/facebook-login/review
If you are indeed trying with an App Admin/Developer/Tester and it still does not work, debug the Access Token in the Debugger and make sure publish_actions is authorized correctly: https://developers.facebook.com/tools/debug/

tweetsharp - app stops being able to tweet after a few hours

I have a asp.net 4.5 webforms site that allows users to link their account to twitter and tweet directly from my site.
My app is registered with twitter and I am able to successfully authorise my app for the user's account and initially can tweet fine, but after a few hours the tweets stop working. I am using tweetsharp to handle the authorisation.
my code is:
TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
twitterClientInfo.ConsumerKey = ConsumerKey;
twitterClientInfo.ConsumerSecret = ConsumerSecret;
var requestToken = new OAuthRequestToken { Token = oauthtoken };
TwitterService twitterService = new TwitterService(ConsumerKey, ConsumerSecret);
OAuthAccessToken accessToken = twitterService.GetAccessToken(requestToken, oauthverifier);
twitterService.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
TwitterUser user = twitterService.VerifyCredentials(new VerifyCredentialsOptions());
SendTweetOptions options = new SendTweetOptions();
options.Status = tweetText;
twitterService.SendTweet(options);
what i have noticed is that while the app is successfully tweeting, the accessToken.Token value that is being used to authenticate the user has a proper value (a long string of numbers and upper/lowercase characters) however when it stops tweeting the accessToken.Token value is just a single question mark "?".
Twitter says it doesn't expire tokens so i am at a loss to understand what is happening or how it can be resolved? if i went in to my twitter account and deauthorised my app and went through the authorisation again it would work fine for a few hours, but obviously that's not something i can ask my users to do.
can anyone suggest a resolution to this - either to stop the accessToken value becoming ? or to handle it and get a proper value if it does (without reauthorising the app)
Well, without beginning to understand the actual issue, I managed to fix it
Instead of retrieving the access token every time via:
var requestToken = new OAuthRequestToken { Token = oauthtoken };
OAuthAccessToken accessToken = twitterService.GetAccessToken(requestToken, oauthverifier);
twitterService.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
i only do that once and store accessToken.Token and accessToken.TokenSecret in the database and retrieve them when tweeting and supply them
twitterService.AuthenticateWith(accessTokenFromDB, accessokenSecretFromDB);
I have seen somewhere that Twitter doesn't expire tokens, so this should work. Certainly it's been working for me all weekend whereas the original code would stop working after a few hours.
Thought this might help some others who have the same issue.

Facebook C# SDK - Post to wall

I'm developing an asp.net MVC 3 Facebook app and I am trying to post a message to my wall. Here is my code:
FacebookWebClient client = new FacebookWebClient();
// Post to user's wall
var postparameters = new Dictionary<string, object>();
postparameters["message"] = "Hello world!";
postparameters["name"] = "This is a name";
postparameters["link"] = "http://thisisalink.com;
postparameters["description"] = "This is a description";
var result = client.Post("/me/feed", postparameters);
I can get the access token using client.AccessToken, so I'm assuming I don't have to set it anywhere. This code produces no errors and for the result I get an ID. However, when I bring up my Facebook, I see nothing on my wall nor in my news feed. I'm not sure what I'm missing. I've looked at related questions here at StackOverflow, but I see no reports/questions similar to mine. I've also tried changing the code based on what I've seen in other posts, but to no avail. I also checked my Facebook account settings and I see my application listed with permission to post to my wall. I also tried posting a message to my wall via the Graph API explorer and I'm getting the same result. I get an ID in return, but when I check my Facebook account I see nothing. At been at this for a couple of days. Any help would be greatly appreciated.
Thanks in advance.
[EDIT]
I wonder if something is wrong with my app generated access_token. Using this access_token, as I mentioned in my post, I get the same result using the Graph API explorer. An ID is returned, but no message on my wall. However, if I give the Graph API explorer permission to post to my wall and use its own generated access_token, I can successfully post a message using the explorer. Here's the FB login button code:
<div>
<h1>Login using Facebook</h1>
<p><fb:login-button perms="user_location, publish_stream, email"></fb:login-button></p>
</div>
Basically you need to add an additional parameter into your post parameters.
args["access_token"] = account.access_token;
this is the token of the specific page.
I wont repeat the code, follow here for example: Post On Facebook Page As Page Not As Admin User Using Facebook C# SDK
(second answer)
Did you request right App permissions to Facebook in your action method?
Try: [CanvasAuthorize(Permissions = "user_location, publish_stream, email")]
Did you append the access_token to the URL? See example here. It's also documented here (see Using the Access Token).
/me/feed?access_token=<access_token>
with one small change, your code works fine for me. you have to pass the users auth token into the constructor like this...
var client = new FacebookClient(accessToken);
// Post to user's wall
var postparameters = new Dictionary<string, object>();
postparameters["message"] = "Hello world!";
postparameters["name"] = "This is a name";
postparameters["link"] = "http://thisisalink.com;
postparameters["description"] = "This is a description";
var result = client.Post("/me/feed", postparameters);
this method works for me, although i am not sure which facebook sdk you are using.
i'm using http://facebooksdk.net/ its quite good so if you're not using it i would recommend it

Categories