I tried to post to users wall using application access token but it still posts from users name. Is it possible to post from application's name?
var fbc = new FacebookWebClient();
var wc = new WebClient();
var tokenStr = wc.DownloadString(string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials",
FacebookApplication.Current.AppId, FacebookApplication.Current.AppSecret));
fbc.AccessToken = tokenStr.Replace("access_token=", string.Empty);
dynamic parameters = new ExpandoObject();
parameters.message = "testMessage";
//parameters.link = pageLink;
parameters.name = "testCaption";
dynamic result = fbc.Post(string.Format("{0}/feed", userID), parameters);
var fbPost = new FacebookClient ( accessToken );
dynamic result = fbPost.Post ( "me/feed", new { message = "Welcome to C# SDK and me" } );
Related
I am trying to update the subscription expiry for my graph token. This is an application based subscription.
This is what I have tried:
var tokenExpiry = DateTime.UtcNow.AddMinutes(4230).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.0Z");
Lookup lp = new Lookup();
string access_token = "{MYACCESSTOKEN}";
_CreateRequestBody requestBody = new _CreateRequestBody
{
expirationDateTime = tokenExpiry
};
RestClient rc = new RestClient();
rc.EndPoint = "https://graph.microsoft.com/v1.0/subscriptions/" + subscriptionId;
rc.AccessToken = access_token;
rc.Method = HttpVerbs.PATCH;
rc.PostData = JsonConvert.SerializeObject(requestBody);
Error message is Invalid: expirationDateTime and its value must be included in the payload.
I search on graph api that when post video have backdated_post parameter.
But I dont know how to declare it.
On https://developers.facebook.com/docs/graph-api/reference/video, that backdated_post is json array have 3 paramter inside : backdated_time, backdated_time_granularity, hide_from_newsfeed.
And I declare [{"backdated_time": "2/12/2016"}], graph api show me error : "backdated_time not declare" or something simaliar.
Graph api I'm using that ver 2.10.
This is my code
var url = $"https://graph-video.facebook.com/v2.10/{idOrUserNameOfPage}/videos?access_token={accessTokenPage}";
using (var content =
new MultipartFormDataContent(AnotherUtils.GenerationBoundary()))
{
var streamContent = new StreamContent(streamVideo);
var videoContent = new ByteArrayContent(await streamContent.ReadAsByteArrayAsync().ConfigureAwait(false));
streamContent.Dispose();
videoContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
StringContent messageContent = new StringContent(message, Encoding.UTF8);
List<dynamic> listDynamic = new List<dynamic>();
listDynamic.Add(new
{
backdated_time = datePost,
backdated_time_granularity = "none",
hide_from_newsfeed = false
});
var jsonString = JsonConvert.SerializeObject(listDynamic);
StringContent postDatePageContent = new StringContent(jsonString,Encoding.UTF8, "application/json");
content.Add(postDatePageContent, "backdated_post");
content.Add(messageContent, "description");
content.Add(videoContent, "file", "file.mp4");
var response = await _customHttpClient.PostAsync(url, content).ConfigureAwait(false);
}
And facebook show error : (#100) Invalid format for BackdatedPost, backdated_time must be defined.
Anyone help me ?? pls
My problem is only donwload. Tomorrow I have 2 problem they are download and upload. But I solve upload problem. I can share upload code this questions answer. But now only problem download
P.S =Client application
var authenticator = new ClientLoginAuthenticator("ApplicationName", ServiceNames.Documents, new GDataCredentials("Username", "Password"));
var service = new DocumentsService("ApplicationName");
var entry = new DocumentEntry();
entry.Title.Text = fileName;
entry.MediaSource = new MediaFileSource(filePath, "application/pdf");
var createUploadUrl = new Uri(String.Format(UploadPath, "uploadFileId"));
var link = new AtomLink(createUploadUrl.AbsoluteUri);
link.Rel = ResumableUploader.CreateMediaRelation;
entry.Links.Add(link);
entry.Service = service;
var uploader = new ResumableUploader();
var response = uploader.Insert(authenticator, entry);
return response.ResponseUri.AbsolutePath;
string UploadPath = "https://docs.google.com/feeds/upload/create-session/default/private/full/folder:{0}/contents";
I want to import data from Google Analytics.
var gas = new AnalyticsService(auth);
var r = gas.Data.Ga.Get("ga:6332XXXX", "2013-02-01", "2013-02-11", "ga:visits");
r.Dimensions = "ga:date";
r.Sort = "ga:visits";
r.StartIndex = 1;
var data = r.Fetch();
I get 400 bad request error in Fetch method. What is the wrong of my code?
My full code like following:
var scope = AnalyticsService.Scopes.AnalyticsReadonly.ToString();
var clientId = "--------.apps.googleusercontent.com";
var keyFile = #"C:\-----------------privatekey.p12";
var keyPassword = "notasecret";
var desc = GoogleAuthenticationServer.Description;
var key = new X509Certificate2(keyFile, keyPassword, X509KeyStorageFlags.Exportable);
var client = new AssertionFlowClient(desc, key)
{
ServiceAccountId = clientId,
Scope = scope
};
var auth = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);
var gas = new AnalyticsService(auth);
var r = gas.Data.Ga.Get("ga:6332XXXX", "2013-02-01", "2013-02-11", "ga:visits");
r.Dimensions = "ga:date";
r.Sort = "ga:visits";
r.StartIndex = 1;
var data = r.Fetch();
Thaks for your interest.
A couple of ideas:
your clientId should be your SERVICE ACCOUNT EMAIL (not id)
your scope should be "https://www.googleapis.com/auth/analytics.readonly"
If this doesn't work, check #Martyn's answer
I am using Facebook c# SDK to post status & images on users wall.
I am able to post status but image is not getting posted
Here is my code:
[HttpPost]
public ActionResult PostPhotoOnWall(HttpPostedFileBase file)
{
var client = new FacebookClient();
// Post to user's wall
var postparameters = new Dictionary<string, object>();
postparameters["access_token"] = Session["access_token"].ToString();
postparameters["picture"] = "http://localhost:8691/Content/themes/base/images/12WIPJ50240-2V91.jpg";
var result = client.Post("/me/feed", postparameters);
return View("PostPhoto");
}
On user wall status is posted without image.
Can any one help me .
I Solved It, Bellow is the code
[HttpPost]
public ActionResult PostPhotoOnWall(HttpPostedFileBase file)
{
var filename = Path.GetFileName(file.FileName);
var client = new FacebookClient();
// Post to user's wall
var postparameters = new Dictionary<string, object>();
var media = new FacebookMediaObject
{
FileName = filename,
ContentType = "image/jpeg"
};
var path = Path.Combine(Server.MapPath("~/Content/themes/base/images"),filename);
file.SaveAs(path);
byte[] img = System.IO.File.ReadAllBytes(path);
media.SetValue(img);
postparameters["source"] = media;
postparameters["access_token"] = Session["access_token"].ToString();
// postparameters["picture"] = "http://localhost:8691/Content/themes/base/images/12WIPJ50240-2V91.jpg";
var result = client.Post("/me/photos", postparameters);
return View("PostPhoto");
}