How to post media on google plus through google api? - c#

private void googleplue()
{
Moment body = new Moment();
ItemScope itemScope = new ItemScope();
itemScope.Id = "replacewithuniqueforaddtarget";
itemScope.Image = "http://www.google.com/s2/static/images/GoogleyEyes.png";
itemScope.Type = "";
itemScope.Description = "The description for the action";
itemScope.Name = "An example of add activity";
body.Object = itemScope;
body.Type = "http://schema.org/AddAction";
MomentsResource.InsertRequest insert =
new MomentsResource.InsertRequest(
plusService,
body,
userId,
MomentsResource.Collection.Vault);
// Moment wrote = insert.Fetch();
}
I tried this but not work please give me any other solution.

Moment isn't the same as posting to Google+ timeline its not possible to post to the Google+ timeline. see Issue 41: Write access to the streams
In order to post moments which isn't the same thing, you need to be able to set request_visible_actions as part of the authentication process and it doesn't appear that its possible to do with with the current version of the C# client library see
If you want to post moments and not write to a user time line then your going to have to figure out how to send the request_visible_actions as part of your authentication. if you do figure out how to do that please post the answer on my question.

Related

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/

how to post on facebook wall for specific list of users using asp.net c#?

I am trying to post on specific group of users on facebook such as (close friends, or family, or college friend...) and I used the code bellow.
code that I used:
1
FacebookClient fpost1 = new FacebookClient(access_token);
fpost1.Post("/1234567890/feed", new { message = "test post"});
note: access_token is working correctly when I am doing some job before this exception.
I put my friendlist id instead of 1234567890, that you can get it from graph .../me?fields=friendlists
it did not work and gave me this error "(OAuthException - #2) An unexpected error has occurred. Please retry your request later."
2
FacebookClient fpost1 = new FacebookClient(access_token);
fpost1.Post("/me/feed", new { message = "it is very cold.", to="1234567890"});
this one work, but it post to "only me" as target.
thank you
It looks to me that what you are doing here...
FacebookClient fpost1 = new FacebookClient(access_token);
fpost1.Post("/1234567890/feed", new { message = "test post"});
is wrong. Because I believe that 1234567890 is a user-id, right? Not a friendslist-id. According to the documentation this edge/endpoint signature goes like....
/{user-id}/feed
where user-id is obviously a user id. The documentation states that...
Most nodes in the Graph API have edges that can be published to (such as Photos or Posts). All Graph API publishing is done simply with an HTTP POST request to the relevant endpoint with any necesssary parameters included. For example, if you wanted to publish a post on behalf of someone, you would make an HTTP POST request as below:
POST graph.facebook.com
/{user-id}/feed?
message={message}&
access_token={access-token}
Notice that it says "On Behalf of Someone". My understanding is that you are publishing on behalf of someone and to do that, this someone must have requested an access_token through your application. In other words, if this user hasn't logged in to your app and generated a valid access token you cannot publish on his/her wall
POST graph.facebook.com
me/feed?message="hello"&privacy={"value": "CUSTOM", "allow": "1234567890"}
where the 1234567890 is one of friendlists id

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

DotNetOpenAuth with Google Calendar Feed

I have been racking my brain for a few days trying to get a list of calendars from Google using DotNetOpenAuth.
I can successfully get a list of contacts using the DotNetOpenAuth Samples. I have integrated it with my domain using the OpenId+OAuth. Everything works great to get a list of contacts.
So from there I modified the code to try to retrieve a list of Calendars and I keep getting a 401 Unauthorized error.
I know it is authorizing because I can get the contact list. Does anyone have a code example how they are retrieving calendars or calendar events using the DotNetOpenAuth with Google???
Thanks
Update:
Thanks for the response. I have read everything I can get my hands on. Here is what I have done so far
Step 1: I created a new GetCalendarEndPoint in the GoogleConsumer.cs
private static readonly MessageReceivingEndpoint GetCalendarEndpoint = new MessageReceivingEndpoint("https://www.google.com/calendar/feeds/default", HttpDeliveryMethods.GetRequest);
Step 2: Next I created a new method GetCalendars patterned after the GetContacts Method in GoogleConsumer.cs - (Rebuilt the dll etc.)
public static XDocument GetCalendars(ConsumerBase consumer, string accessToken, int maxResults/* = 25*/, int startIndex/* = 1*/) {
if (consumer == null)
{
throw new ArgumentNullException("consumer");
}
var request = consumer.PrepareAuthorizedRequest(GetCalendarEndpoint, accessToken);
var response = consumer.Channel.WebRequestHandler.GetResponse(request);
string body = response.GetResponseReader().ReadToEnd();
XDocument result = XDocument.Parse(body);
return result;
Step 3: In my Application I modified the ScopeURI to the the Calendar URI from GoogleConsumer as follows
private IAuthenticationRequest GetGoogleRequest()
{
Realm realm = Request.Url.Scheme + Uri.SchemeDelimiter + Global.GoogleTokenManager.ConsumerKey + "/";
IAuthenticationRequest authReq = relyingParty.CreateRequest(GoogleOPIdentifier, realm);
// Prepare the OAuth extension
string scope = GoogleConsumer.GetScopeUri(GoogleConsumer.Applications.Calendar);
Global.GoogleWebConsumer.AttachAuthorizationRequest(authReq, scope);
// We also want the user's email address
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
authReq.AddExtension(fetch);
return authReq;
}
However, when I run the app I get 401 Unauthorized when I make the following call
var calendars = GoogleConsumer.GetCalendars(Global.GoogleWebConsumer, State.GoogleAccessToken, 25, 1);
I have also checked that the State.GoogleAccess token exists by simply displaying it on my screen before I trigger the method that makes this call.
Again, if I exectute
var calendars = GoogleConsumer.GetContacs(Global.GoogleWebConsumer, State.GoogleAccessToken, 25, 1);
then it works??????? Thanks for you help.
I've been suffering through exactly the same thing for most of the weekend.
I think that after much fiddling with Fiddler I've found the cause and have a solution which, although not pretty, seems to work. I found that I was able to access the calendar feed by copying and pasting the DNOA-generated Uri into a browser, but always got a 401 when attempting programmatic access. This is apparently because the default auto-redirect behavior of HttpWebRequest discards any cookies that the redirect is attempting to set. The Contacts feed doesn't set any cookies during the redirect, so it is immune.
The first time you request a calendar feed (even with a properly constructed and signed OAuth request), Google replies with a redirect containing a cookie. If you don't present that "calendar cookie" at the same time as your feed request you will get a 401 Unauthorized when you attempt to follow the redirect to the feed.
here's the cookie-setting header from Google:
HTTP/1.1 302 Moved Temporarily
Set-Cookie: S=calendar=y7AlfgbmcqYl0ugrF-Zt9A;Expires=Tue, 10-Jan-2012 03:54:20 GMT;Secure
Here's what I'm doing to make it work:
// wc: WebConsumer
var calRequest = wc.PrepareAuthorizedRequest(erp2, authTokenRsp.AccessToken);
// need to stop redirect to capture calendar cookie token:
calRequest.AllowAutoRedirect = false;
var calResponse = calRequest.GetResponse();
var redirectCookie = calResponse.Headers[System.Net.HttpResponseHeader.SetCookie];
var cookiedCalRequest = wc.PrepareAuthorizedRequest(erp2, authTokenRsp.AccessToken);
cookiedCalRequest.Headers[System.Net.HttpRequestHeader.Cookie] = redirectCookie;
var calFeedResponse = cookiedCalRequest.GetResponse();
Have you read the Google Calendar data API documentation to make sure you have the right endpoints programmed in? Have you also modified the code that acquires the access token to request access to Google Calendar in addition to Google Contacts? The access token in the sample only gets Contacts permissions unless you change it.

Categories