I'm developing a new update for my existing Windows 8.1 app (written in C#). On this update, I would like the users to connect to Facebook. I found a lot of tutorials to make this work but I still don't have a solution.
When the WebAuthenticationBroken is called I have the Facebook login page (with Facebook logo and email and password fields) but on the top I have this:
Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. must match the Website URL or Canvas URL, or the domain must be a of one of the App's domains.
When I fill my info and click on Login I got an error like this from the WebAuthenticatonBroken UI: (I'm not using my Windows in English, so I don't know how it is exactly written)
We couldn't connect to the service right now. Check your internet connection or try again later.
My Facebook app is live, the SID is defined on the Windows Store ID field on basic settings.
Here I have my C# code used to call the WebAuthenticationBroker on my Windows 8.1 app:
public Uri _callbackUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
public string FacebookAppId = "15911339xxxxxxxx";
public string FacebookPermissions = "public_profile,email,user_friends";
FacebookClient _fb = new FacebookClient();
var loginUrl = _fb.GetLoginUrl(new
{
client_id = FacebookAppId,
redirect_uri = _callbackUri.AbsoluteUri,
scope = FacebookPermissions,
display = "popup",
response_type = "token"
});
WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(
WebAuthenticationOptions.None,
loginUrl);
if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
{
var callbackUri = new Uri(WebAuthenticationResult.ResponseData.ToString());
var facebookOAuthResult = _fb.ParseOAuthCallbackUrl(callbackUri);
FacebookClient fbclient = new FacebookClient(facebookOAuthResult.AccessToken);
dynamic result = await fbclient.GetTaskAsync("me");
string id = result.id;
string email = result.email;
string FBName = result.name;
ApplicationData.Current.RoamingSettings.Values["UserID"] = id;
var accessToken = facebookOAuthResult.AccessToken;
}
I've already tried with no Valid OAuth redirect uri and with the "https://www.facebook.com" as well, but it's still not working.
I've also tried setting the "Embedded browser OAuth Login" and the "Native or desktop app?" on.
I'm using the most recent Facebook SDK for Windows Store.
I hope someone can help me fix this error.
PS: sorry for my bad English...
Thanks,
Rafael Pedro da Silva
Ok, I got it :) It's working now.
I just had to set the redrect url ( "FacebookClient().GetLoginUrl()" and on the callbackUri of the WebAuthenticationBroker ) and on Facebook settings to "https://www.facebook.com/connect/login_success.html".
Related
I use asp.net MVC webapi, and have been using facebook login for a long time. But suddenly there is an error as below:
bellow my code: Startup.Auth.cs
FacebookAuthenticationOptions options = new FacebookAuthenticationOptions();
options.AppId = ConfigurationManager.AppSettings["FBappId"];
options.AppSecret = ConfigurationManager.AppSettings["FBappSecret"];
string[] FBScopes = ConfigurationManager.AppSettings["FBScope"].ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in FBScopes)
{
options.Scope.Add(s);
}
Microsoft.Owin.Security.Twitter.Messages.RequestToken request = new Microsoft.Owin.Security.Twitter.Messages.RequestToken();
options.Provider = new FacebookAuthenticationProvider()
{
OnAuthenticated = async context =>
{
//Get the access token from FB and store it in the database and
//use FacebookC# SDK to get more information about the user
context.Identity.AddClaim(
new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
}
};
options.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie;
//options.SignInAsAuthenticationType = Microsoft.Owin.Security.AppBuilderSecurityExtensions.GetDefaultSignInAsAuthenticationType(app);
app.UseFacebookAuthentication(options);
So far it's working fine and no such error ever appeared. Anyone know why this happens?
Have there been any security changes by facebook?
Advice me please.
I had the same problem, in my case, the solution was to remove android aplication in the facebook.
In my case, it was the "Valid OAuth redirect URIs" property which was set to an old redirect URI I had set before.
Once I changed it to the current port, it worked correctly.
This setting is in the "Products=>Facebook Login" section.
First thing first, I never used SDK before and I don't know what does token mean. I am searching for the most simple solution, if possible without SDK, without token, without FB App.
I have a button in my C# application and when the user clicks on it I want a popup window where the user can login to Facebook or if he is logged in he can push the share button in order to share the predefined content.
While searching on the internet I found this code:
var client = new FacebookClient("my_access_token");
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://www.example.com/article.html";
parameters.picture = "http://www.example.com/article-thumbnail.jpg";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.actions = new {
name = "View on Zombo",
link = "http://www.zombo.com",
};
parameters.privacy = new {
value = "ALL_FRIENDS",
};
parameters.targeting = new {
countries = "US",
regions = "6,53",
locales = "6",
};
dynamic result = client.Post("me/feed", parameters);
But this example uses Facebook SDK and it needs token. I want a simple solution, without SDK, without FB APP. I want a simple popup with predefined text.
Is there any solution?
An access token is an opaque string that identifies a user, app, or page and can be used by the app to make graph API calls.
Access Tokens identifies an app ,user or page
Without creating an app from facebook and getting a token you cannot proceed in this case(c# application).
I have a website made with ASP.NET webform .NET 4.5 C#. This site contains a forum(homemade by me), parts of this forum needs to be posted to the specific facebook wall(made for this webpage). What I need :
Post just created thread(message) from specific part of the forum to the corsponding facebook wall.
Optional : Sync the forum thread on webpage with message/comments on the specific facebook page
I have looked at these guides :
http://www.codeproject.com/Articles/569920/Publish-a-post-on-Facebook-wall-using-Graph-API
http://www.c-sharpcorner.com/UploadFile/raj1979/post-on-facebook-users-wall-using-Asp-Net-C-Sharp/
But im not sure that this is really the solution for me? I have tried to follow the guide but it does not look the same.
Edit :
dynamic result;
//https://developers.facebook.com/tools/explorer/
//https://developers.facebook.com/tools/access_token/
FacebookClient client = new FacebookClient(ConfigurationManager.AppSettings["FacebookAppToken"]);
//result = client.Get("debug_token", new
//{
// input_token = ConfigurationManager.AppSettings["FacebookAppToken"],
// access_token = ConfigurationManager.AppSettings["FacebookAppToken"]
//});
//result = client.Get("oauth/access_token", new
// {
// client_id = ConfigurationManager.AppSettings["FacebookAppId"],
// client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
// grant_type = "client_credentials",
// //redirect_uri = "http://www.MyDomain.net/",
// //code = ""
// });
result = client.Get("oauth/access_token", new
{
client_id = ConfigurationManager.AppSettings["FacebookAppId"],
client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
grant_type = "client_credentials"
});
client.AccessToken = result.access_token;
result = client.Post("[IdOfFacebookPage]/feed", new { message = "Test Message from app" });
//result.id;
result = client.Get("[IdOfFacebookPage]");
return false;
Approach to post to a facebook wall:
You need to register in facebook developer tools.
Create a app (fill a form).
Download FGT 5.0.480 (Facebook graph toolkit)
Reference FGT dlls in your web application.
FGT has methods to post to facebook wall but needs appId.
Use the app id of your app created in step 2.
To post to an user's wall through facebook, it is only possible through an app.
Try this asp .net app, which will allow you to post in your wall:
https://apps.facebook.com/aspdotnetsample/?fb_source=search&ref=br_tf
This will allow you to envision what you need.
Your app gets an appId with which you need to generate auth token.
Limitation: The user's wall where you want to post should have added the app created at step 2, this is compulsory and there is no work around.
When the user accesses the app for the first time, it automatically asks for permission to post to wall--> the user needs to accept it.
Hope this gives you an idea on how to go about doing this.
You can then post into the user's wall.
For Banshee's below request using Facebook SDK for .NET:
userId - facebook user id, wall to post the message
This user should have added the app created by you in step 1 else it will say unauthorized access.
dynamic messagePost = new ExpandoObject();
messagePost.picture = "http://www.stackoverflow.com/test.png";
messagePost.link = "http://www.stackoverflow.com";
messagePost.name = "This is a test name";
messagePost.caption = "CAPTION 1";
messagePost.description = "Test desc";
messagePost.message = "message"
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new {
client_id = "app_id",
client_secret = "app_secret",
grant_type = "client_credentials"
});
fb.AccessToken = result.access_token;
try
{
var postId = fb.Post(userId + "/feed", messagePost);
}
catch (FacebookOAuthException ex)
{
//handle oauth exception
}
catch (FacebookApiException ex)
{
//handle facebook exception
}
You will need an extended token to publish to a wall.. Steps to get extended token is explained well by Banshee..
Edit: How to get extended token by Banshee:
Please follow this post
By creating a extended page token and use it to make the post everything works just fine. See this : How to get Page Access Token by code?
Im surprised that this simple task was so hard to get running and that there was vary little help to get.
I need to show images of a specific instagram user on my webpage.
As stated in the Instagram API documentation I need to get authenticated to be able to "browse" a user's feed.
"We only require authentication in cases where your application is making requests on behalf of a user (commenting, liking, browsing a user’s feed, etc.)."
(http://instagram.com/developer/authentication/)
So as stated in the API documentation, I send a request to this URL:
https://instagram.com/oauth/authorize/?display=touch&client_id=[ClientID]
&redirect_uri=[callbackuri]/&response_type=token
to be redirected to another URL: http://your_redirect_uri?code=CODE to be able to get the access_token (CODE) to be able to call the instagram RESTful services with it.
The problem is that if my website visitor is not logged in to Instagram, he/she will be forwarded to a login page to authenticate first and only then I can get an access token.
My question is: how can I bypass this login page by automatically login with my application's instagram account from the codebehind (or probably by javascript!)?
I am using C# and Instasharp(http://instasharp.org/) by the way.
Any ideas?
Thank you in advance!
first of create Developer app in Instagram and get consumerkey & consumersecret and set path call back url somthing link http://localhost:3104/Instagram.aspx
private void Authentication()
{
string rest = string.Empty;
GlobusInstagramLib.Authentication.ConfigurationIns config = new GlobusInstagramLib.Authentication.ConfigurationIns("https://instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["consumerKey"], ConfigurationManager.AppSettings["consumerSecret"], ConfigurationManager.AppSettings["callbackurl"], "https://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
oAuthInstagram _api = oAuthInstagram.GetInstance(config);
rest = _api.AuthGetUrl("likes+comments+basic+relationships");
Response.Redirect(rest);
}
Automatic redirect on this page and call this code
public void Instagram()
{
string code = (String)Request.QueryString["code"];
oAuthInstagram objInsta = new oAuthInstagram();
GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["consumerKey"], ConfigurationManager.AppSettings["consumerSecret"], ConfigurationManager.AppSettings["callbackurl"], "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
oAuthInstagram _api = new oAuthInstagram();
_api = oAuthInstagram.GetInstance(configi);
AccessToken access = new AccessToken();
access = _api.AuthGetAccessToken(code);
string accessToken = access.access_token;
string id =access.user.id;
}
you will get token and user id
I am trying to implement user registration on my mvc3 site using fb. My question is regard this bit of code
FacebookClient fbClient = new FacebookClient(accessToken);
dynamic me = fbClient.Get("me?fields=id,name");
What other parameters can be specified in the request "me?fields=id,name,??". My application requires Email Address, phone number, address and name (first name, last name). I would be grateful if someone could tell me or better yet point to to somewhere I can find documentation on this.
This is a sample of the parameters you get inside dynamic me = fb.Get("me") without user permission:
"id":"894555532"
"name":"John Doe"
"first_name":"John"
"last_name":"Doe"
"link":"http://www.facebook.com/johndoe"
"username":"john"
"bio":"Sample bio"
"quotes":"\"Sample quote""
"work":[{"employer":{"id":"39233323343","name":"Sample Company"}
"position":{"id":"142461033332450","name":"Backend Developer"}
"projects":[{"id":"214103971985333"
"name":"Coors Light, Sample Project"}]}]
"favorite_teams":[{"id":"171522852874952","name":"Juventus"},{"id":"112325268793829","name":"Barcelona F.C."}]
"favorite_athletes":[{"id":"326971266226","name":"Alessandro Del Piero"}]
"gender":"male"
"timezone":-6
"locale":"en_US"
"verified":true
"updated_time""2012-01-24T09:12:17+0000"}
"email" requires user permission
I'm sure there are other things you can get, though there is no official list for c# sdk yet.
This is a sample of how to get all that info:
var fb = new FacebookWebClient();
dynamic me = fb.Get("me");
imgProfilePic.ImageUrl = string.Format("https://graph.facebook.com/{0}/picture", me.id);
lblName.Text = me.name;
lblFirstName.Text = me.first_name;
lblLastName.Text = me.last_name;
Here's an updated / complete list a scopes for Facebook C# SDK:
ads_management
create_event
create_note
email
export_stream
friends_about_me
friends_activities
friends_birthday
friends_checkins
friends_education_history
friends_events
friends_games_activity
friends_groups
friends_hometown
friends_interests
friends_likes
friends_location
friends_location_posts
friends_notes
friends_online_presence
friends_photo_video_tags
friends_photos
friends_questions
friends_relationship_details
friends_relationships
friends_religion_politics
friends_status
friends_subscriptions
friends_videos
friends_website
friends_work_history
manage_friendlists
manage_notifications
manage_pages
offline_access
photo_upload
publish_actions
publish_checkins
publish_stream
read_friendlists
read_insights
read_mailbox
read_requests
read_stream
rsvp_event
share_item
sms
status_update
user_about_me
user_activities
user_birthday
user_checkins
user_education_history
user_events
user_games_activity
user_groups
user_hometown
user_interests
user_likes
user_location
user_location_posts
user_notes
user_online_presence
user_photo_video_tags
user_photos
user_questions
user_relationship_details
user_relationships
user_religion_politics
user_status
user_subscriptions
user_videos
user_website
user_work_history
video_upload xmpp_login