I can successfully post to Facebook, however the posts are not public that everyone can see, only the primary page admin. Even after manually going through each post and "approving" them they are still not publicly available. I posted the question to Facebook and got a thank you for posting a question but no answer.
I created a Facebook app then using Facebook Graph API I got some access tokens for the app and made the access token permanent.
I can post using the Facebook SDK for .Net but again on the primary page admin can see the posts and nothing will make them visible.
Here is the access token info:
App ID 435958876564133 : RROADSus
Profile ID 830833833664593 : RROADSus
User ID
596954487156779 : Janel Xxxxx
User last installed this app via API N/A
Issued 1487528725 (about a month ago)
Expires Never
Valid True
Origin Web
Scopes manage_pages, publish_pages, pages_manage_cta, publish_actions, public_profile
Here is the code in the class to post to Facebook:
public static void postGotRV_FB(string Msg, string Picture, string Link, string Caption, string Desc)
{
string fb_Token = ConfigurationManager.AppSettings["fb:PermToken"];
FacebookClient client = new FacebookClient(fb_Token);
dynamic messagePost = new ExpandoObject();
messagePost.access_token = fb_Token;
messagePost.message = Msg.ToString().Trim();
if (string.IsNullOrEmpty(Picture) == false)
{
Picture = Picture.Replace("../", "http://www.RROADS.us/");
messagePost.source = Picture;
}
if (string.IsNullOrEmpty(Link) == false)
messagePost.link = Link.ToString().Trim();
if (string.IsNullOrEmpty(Caption) == false)
messagePost.caption = Caption.ToString().Trim();
if (string.IsNullOrEmpty(Desc) == false)
messagePost.description = Desc;
var result = client.Post("/830833833664593/feed", messagePost);
}
Here is the code I am calling to test the function off a button keypress:
protected void Unnamed1_Click(object sender, EventArgs e)
{
//string image = "Got-RV.png";
string image = "../Images/RROADS.png";
string Msg = "Hello From RROADS.us";
string Link = "http://www.RROADS.us";
string Caption = "Image Caption";
string Desc = "This is my test Description";
SocialMedia.postGotRV_FB(Msg, image, Link, Caption, Desc);
}
The post appears when you view the page as admin :
Hello From RROADS.us
<< IMAGE IS HERE >>
The Heart of Your Adventure
This is my test Description
IMAGE CAPTION
But when you view the page as anyone else this post does not appear.
What am I missing?
Thank you in advance!
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();
}
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".
I am building a Asp.net C# application i want to post the user uploaded picture directly to Instagram, but after a quick search i can not found any function in the API somebody help me how to post image on instagram wall by C# code
Below Code I can Get Access Token
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);
}
// Call back Url
public ActionResult 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;
ViewBag.accessToken = accessToken;`enter code here`
ViewBag.Uid = id;
return View();
}
Below Code i have get Access Token and Profile ID
How To Post Image ? some body tall me
You cannot upload photos to Instagram through the API. From Instagram's API documentation https://instagram.com/developer/endpoints/media/:
At this time, uploading via the API is not possible. We made a
conscious choice not to add this for the following reasons:
Instagram is about your life on the go – we hope to encourage photos from within the app.
We want to fight spam & low quality photos. Once we allow uploading from other sources, it's harder to control what comes into the
Instagram ecosystem. All this being said, we're working on ways to
ensure users have a consistent and high-quality experience on our
platform.
I am trying to post on my Facebook page using c# and Facebook sdk. I am able to post the contents on my Facebook page but it is not properly visible to others. Even the admin of the page can view only the heading of the post but can not see the picture or the content of that post. But the admin of the page can see the contents of the post by clicking on ">" this sign beside post to page. Please guide me why this is happening and how can I resolve this.
protected void Page_Load(object sender, EventArgs e)
{
CheckAuthorization();
}
private void CheckAuthorization()
{
string app_id = "My App ID";
string app_secret = "My App Secret";
string scope = "publish_stream, publish_actions";
if (Request["code"] == null)
{
Response.Redirect(string.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}", app_id, Request.Url.AbsoluteUri, scope));
}
else
{
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",app_id,Request.Url.AbsoluteUri,scope,Request["code"].ToString(),app_secret);
HttpWebRequest request = System.Net.WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string vals = reader.ReadToEnd();
foreach (string token in vals.Split('&'))
{
tokens.Add(token.Substring(0, token.IndexOf("=")), token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
}
}
string access_token = tokens["access_token"];
var client = new FacebookClient(access_token);
dynamic parameters = new ExpandoObject();
parameters.message = "Hello This Is My First Post To Facebook";
parameters.link = "http://www.google.com";
parameters.picture = "http://www.mywebsite.com/picture/welcome.jpg";
parameters.name = "Hello Users We welcome you all";
parameters.caption = "Posted By Ashish";
client.Post("/My Facebook Page ID/feed", parameters);
}
}
Please guide me where I am doing wrong since I am trying this for the first time after following certain posts on several websites.
You are using the user access token to post a feed to the page. So, the feeds are posted on behalf the user (not the page), which are visible as summary on the timeline.
If you post the feed on behalf of page admin itself (so that the post is visible normally on the timeline), you need to use the page access token with publish_actions permissions.
And to get the page access token you need to query: /<page-id>?fields=access_token using the normal user token with manage_pages permission.
I just want to add that sometimes your app is in MODE : developer so everything you do is visible only to the developers, it is actually the problem i had, So you need to go to your application Dashboard and look for something like "Review" [i hate giving exact paths because Facebook changes everything every once in a while], and look for something like : Your app is in development and unavailable to the public, put it to public
I am developing a WPF application that needs post on wall of a facebook's Page, and this without login window.
Well, I want to get access token for my facebook page, and this is my code.
var fb = new FacebookClient();
string token = "";
dynamic accounts = fb.Get("/"<USER_ID>"/accounts");
foreach (dynamic account in accounts)
{
if (account.id == <PAGE_ID>)
{
token = account.access_token;
break;
}
}
But I receive a error #104. It is a simple error, that I need a access token to do this operation.
Then I use other code to get the user access token
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = <PAGE_ID>,
client_secret = <APP_SECRET>,
grant_type = "fb_exchange_token",
fb_exchange_token = <USER_TOKEN>
});
But I get error #101:
"Error validating application. Cannot get application info due to a system error."
Someone knows what I have to do?
Thanks!!!
I'm not sure if you've been able to get a never expiring token for the page, so I'll explain you the steps:
Open Graph API Explorer
Select your app from the drop-down
Click "Get Access Token" button, and select the manage_pages permission.
Copy the token and run this in the browser:
https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id={app-id}&client_secret={app-secret}&fb_exchange_token={step-3-token}
Copy the token from step-4 and paste in to the access_token field and call:
/{page-id}?fields=access_token
The token you get now is a never-expiring token, you can validate the same in Debugger .Use this in your app.
But beware, its not recommended to use this token on client side if your app is public.
If you use the fb_exchange_token call, it will give you a token that expires after 60 days. In order to make it work correctly, I had to go through the login web flow to guarantee I got an up-to-date page access token.
Go to the Facebook App dashboard
If you haven't already added the Facebook Login product, click "+ Add Product" and select Facebook Login
Enable the "embedded browser control" option and enter https://www.facebook.com/connect/login_success.html as the allowed redirect URL.
Make a Window with a WebView control on it. The WebBrowser control no longer works; the browser engine powering it is too old.
Add code to listen for the navigation to the success URL:
this.webView.NavigationCompleted += (sender, args) =>
{
if (args.Uri.AbsolutePath == "/connect/login_success.html")
{
if (args.Uri.Query.Contains("error"))
{
MessageBox.Show("Error logging in.");
}
else
{
string fragment = args.Uri.Fragment;
var collection = HttpUtility.ParseQueryString(fragment.Substring(1));
string token = collection["access_token"];
// Save the token somewhere to give back to your code
}
this.Close();
}
};
Add code to navigate to the facebook login URL:
string returnUrl = WebUtility.UrlEncode("https://www.facebook.com/connect/login_success.html");
this.webView.Source = new Uri($"https://www.facebook.com/dialog/oauth?client_id={appId}&redirect_uri={returnUrl}&response_type=token%2Cgranted_scopes&scope=manage_pages&display=popup");
Call window.ShowDialog() to pop up the login window, then grab the user access token.
Create some models to help you out:
public class AccountsResult
{
public List<Account> data { get; set; }
}
public class Account
{
public string access_token { get; set; }
public string id { get; set; }
}
Using the user access token, get the page access token:
FacebookClient userFacebookClient = new FacebookClient(userAccessToken);
var accountsResult = await userFacebookClient.GetTaskAsync<AccountsResult>("/me/accounts");
string pageAccessToken = accountsResult.data.FirstOrDefault(account => account.id == PageId)?.access_token;
if (pageAccessToken == null)
{
MessageBox.Show("Could not find page under user accounts.");
}
else
{
FacebookClient pageFacebookClient = new FacebookClient(pageAccessToken);
// Use pageFacebookClient here
}