Facebook post on page - asp.net

I'm using Facebook SDK 6 and Graph API to publish data from app (ASP.NET) to the page.
Firstly, my app (website) get access token using server flow as described here.
Next, it use this token to publish some text in my page:
Dim fb = New FacebookClient(accessToken)
Dim o As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
o.Add("message", "some text...")
Dim result = fb.Post("/TfdTest/feed", o)
To test it, I browse my website. I allow my site change my facebook page and give permissions (publish_stream, manage_pages). The problem is that final feed appears in "Recent Posts by Others" section:
How can I post feed from page name, not from myself???

in order to use Graph API on behalf of a Page, you need to get Page access token - see here for more details: https://developers.facebook.com/docs/authentication/pages/
Authenticate the user and request the manage_pages permission
Get the list of pages the user manages using token from (1) - https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN
Parse the list and get the PAGE token - and use it to post to the feed.

Related

Asp.net webfroms Google login not working

I have the project and users are login into their account by using Google login I created another project in the Google console developer portal to login with gmail now I got this below error message
Code: 403 Message: Legacy People API has not been used in project {PROJECTID} before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/legacypeople.googleapis.com/overview?project={PROJECTID} then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
I followed this URl and https://console.developers.google.com/apis/api/legacypeople.googleapis.com/overview?project={PROJECTID}
but the page show up this below error many times I click on Retry button nothing has changed.
Error alert in Google Console
I have followed this articles https://www.aspsnippets.com/Articles/Login-with-Google-Account-API-in-ASPNet-and-get-Google-Plus-Profile-details.aspx
The code
GoogleConnect.ClientId = "CODE-1545454545545bpqhocrakp.apps.googleusercontent.com"
GoogleConnect.ClientSecret = "KHDFIUHUHDJHSLDSKJ"
GoogleConnect.RedirectUri = "https://mywebsitedomain.com/Login"
Dim code As String = Request.QueryString("code")
Dim json As String = GoogleConnect.Fetch("me", code)
Dim profile As GoogleProfile = New JavaScriptSerializer().Deserialize(Of GoogleProfile)(json)

get logged in user details with Facebook sdk and .Net

I am following this link to get the logged in users details and using this code snippet below
FacebookClient fb = new FacebookClient(string_access_token_here);
dynamic myInfo = fb.Get("/me")
dynamic myExtraInfo = fb.Get("/me?fields=albums.limit(5).fields(name, photos.limit(2).fields(name, picture, tags.limit(2))),posts.limit(5)");
While I get the basic details in myInfo, in my extra info variable I only end up getting an ID
I suspect I have not crafted the URL properly. Is there something else I need to do?
You need to request the user_photos permission for your access token before you can request albums/photos.
The query itself is fine:
https://developers.facebook.com/tools/explorer?method=GET&path=me%3Ffields%3Dalbums.limit(5).fields(name%2C%20photos.limit(2).fields(name%2C%20picture%2C%20tags.limit(2)))%2Cposts.limit(5)&version=v2.0

Issue with Response.Redirect to another site

I'm creating a gateway app which will control access to various other apps (tools).
On visiting the site the user is identified and a list of tools they have access to is displayed. Clicking the link takes the user to the tool. The URL is affixed with a token as a querystring. The token is encrypted.
On arriving at the tool site the system checks to see if there is a querystring with a token. It checks to see if the token is valid (the date is part of the encryption). If OK then the token is also saved as cookie which is valid for 8h and access is granted.
If the user hits the Tool site directly from a bookmark the system once again checks to see if there is a token and that it is valid. If no token is passed as a querystring then the system will see if it still has a valid cookie. If there is no valid token or cookie the site invokes a response.redirect to the gateway together with two querystrings t and r. t is the tool's numeric ID and r is the Tools URL.
What should happen is that the user will be redirected to the Gateway which will check to see if the user has access to tool id t and if the have redirect back to r with a fresh token appended as a querystring.
My code has the following....
Private GatewayURL As String = "http://GatewayURL/default.aspx?t=2&r="
Private ToolURL As String = "http://ToolURL/default.aspx"
In my page load I have….
…
If AuthenticationPass = False Then
'We are not authenticated...
Response.Redirect(GatewayURL & ToolURL, True)
End If
…
Unfortunately when this is triggered I get the following error...
Invalid path for child request 'http://GatewayURL/default.aspx'. A virtual path is expected.
I've run out of ideas on resolving this.... any help appreciated.
You should URL encode your query string parameters:
Response.Redirect(GatewayURL & HttpUtility.UrlEncode(ToolURL), True)
so that you redirect to:
http://GatewayURL/default.aspx?t=2&r=http%3A%2F%2FToolURL%2Fdefault.aspx
instead of:
http://GatewayURL/default.aspx?t=2&r=http://ToolURL/default.aspx
The second is a pretty broken url.

How would you authenticate client login using REST method in Youtube

I have this call that makes a client log in, but how do i pass the username and email to authenticate the user. What i am trying to do is get all the uploaded files from a particular user YouTube account. This is the client log in I am using but doesn't work:
Dim Str As System.IO.Stream
Dim srRead As System.IO.StreamReader
Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(String.Format("https://www.google.com/accounts/ClientLogin/Email={0}&Password={1}&service=youtube&source=Test", username, password))
Dim resp As System.Net.WebResponse = req.GetResponse
Str = resp.GetResponseStream
srRead = New System.IO.StreamReader(Str)
Me.XMLDocument.LoadXml(srRead.ReadToEnd)
Then when the user authenticates I need to make another request that gets the uploaded videos if the client log in is successful.
you don't need to authenticate to retrieve a user's uploads, just a simple GET request on the YouTube API will get you the data in XML:
http://gdata.youtube.com/feeds/api/users/<username>/uploads
For example, see here for all uploads by HBO Sports.
see here for how to use the YouTube .NET Client Library to retrieve the videos uploaded by a particular User:
http://code.google.com/apis/youtube/2.0/developers_guide_dotnet.html#Retrieving_Uploads

fql.query method returns empty string in asp.net

I have developed a web application 3 months ago to show facebook users by searching username. To access facebook, I have downloaded facebook dll and got application key, and secret key from facebook.
My web application was working fine and displaying records from facebook. yesterday onwards, my application is not working fine. I could not get response when I search by name.
I have tested the fql in the facebook testAPI tool online. That time I can get response. but the same fql I used in my appliation but it could not get response from facebook when I search by name. If I search by uid i can get response from facebook.
here is my code-
facebook.Components.FacebookService fb = new FacebookService();
fb.ApplicationKey = "bfeefa69afdfe81975f0d6136ace3009";
fb.Secret = "9b672d682e1d8befd06382953fc2615b";
fb.IsDesktopApplication = false;
//the below fql gives response as xml.
//select name, profile_url from user where uid = '1730923544' -I can get response for this fql.
//the below fql does not give response as xml. But it gives empty string.
//the below fql does gives us response as xml when i try in facebook testAPI.
//select name, profile_url from user where name = 'Suresh Rajan' -I couldn't get response for this fql.
string s = fb.fql.query("select name, pic_square, profile_url from user where name = 'Suresh Rajan'");
if (String.IsNullOrEmpty(str1))
Response.Write("Empty Response");
else
Response.Write(str1 + " <br />");
how to search by name in facebook fql.
thanks
r.e
Yesterday Facebook was having issues with their API that may have prevented some queries from working. Try it again today and it might work.
Here is facebook's api status page where they report any ongoing issues with the API:
http://developers.facebook.com/live_status.php
If it's still not working for you then it's likely the fix that they deployed for yesterday's issue had a bug in it. Here is a similar bug that occured a while ago that sounds just like this one: http://bugs.developers.facebook.com/show_bug.cgi?id=1359. You should open a new bug on the facebook bug tracker if that's the case since that one is old and has already been closed.

Resources