I have a problem when uploading videos to Facebook.
I use Facebook SDK for Android: https://github.com/facebook/facebook-android-sdk to get the access token with the following permissions: "publish_stream","email","video_upload","publish_actions"
Then I send token to the server, which should upload the video. The server tries to upload video using following code:
string fullurl = string.Format("https://graph-video.facebook.com/me/videos?title={0}&description={1}&access_token={2}", HttpUtility.UrlEncode(fileName), HttpUtility.UrlEncode(description), token);
Facebook returns an error:
System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.WebClient.UploadFile(Uri address, String method, String fileName)
at System.Net.WebClient.UploadFile(String address, String fileName)
But, when I check token with the following link: https://graph.facebook.com/me?access_token=myToken Facebook returns user info. That means that token is valid. But, if this request returns error code, where I can find information about error codes?
This solution works perfectly for some users, for other users it works unstable ( 4 of 6 videos uploading failed. Facebook returns that: "connection closed by remote server"). And have not worked for some users with error: "The remote server returned an error: (400) Bad Request".
What is wrong in my code?
I've solve the problem. I have start using facebook SDK for .NET http://facebooksdk.net/ and it works for me.
Facebook.FacebookClient fb = new FacebookClient(facebookEditTask.facebookToken);
fb.PostCompleted += (o, e) =>
{
if (e.Cancelled || e.Error != null)
{
return;
}
var result = e.GetResultData();
facebookVideoUrl = CreateLinkToVideo(result.ToString());
};
dynamic parameters = new ExpandoObject();
parameters.source = new FacebookMediaStream
{
ContentType = "video/mp4",
FileName = Path.GetFileName(facebookEditTask.FilePath)
}.SetValue(File.OpenRead(facebookEditTask.FilePath));
parameters.message = fbMessage;
Task t = fb.PostTaskAsync("me/videos",
new { message = fbMessage, parameters.source });
Related
I have an app that I am trying to create a Facebook bot for and it needs to send photo cards to users. However, to do so I need to get a Facebook attachment_id because I can't upload my files directly from the web. (https://developers.facebook.com/docs/messenger-platform/reference/attachment-upload-api/)
My app is on Firebase, for some reason when I try the URL it gives me this error:
{
"error": {
"message": "(#546) The type of file you're trying to attach isn't allowed. Please try again with a different format.",
"type": "OAuthException",
"code": 546,
"error_subcode": 1545026,
"fbtrace_id": "H8qfi28cNvp"
}
}
That happens with any URL I try but here is a test https://memes-dev.mymemestore.com/mms-tp1pESD7hgWWLiOUziHz.jpg
So I try to use the Google Cloud Storage nodejs api to get a readstream and send that like so
const stream = gcs().bucket('my bucket').file('mms-tp1pESD7hgWWLiOUziHz.jpg').createReadStream();
const message = new formdata();
message.append('message', '{"attachment":{"type":"image", "payload":{"is_reusable":true}}}');
message.append('filedata', stream);
fetch('https://graph.facebook.com/v2.6/me/message_attachments?access_token=<PAGE ACCESS TOKEN>',
{
method: 'POST',
headers: message.getHeaders(),
body: message
})
.then(res => {
console.log(res);
return res.json();
})
.then(json => {
console.log(json);
});
but that gives me the following error
(#100) Incorrect number of files uploaded. Must upload exactly one file.
Does anyone know what is going on?
Thanks
One thing I forgot to mention was that this all had to be done serverless. But I got around it by downloading the image to a tmpdir using tmpdir = path.join(os.tmpdir(), filename) and then fs.createReadStream(tmpdir) and that is working.
I am busy with a angular4 web app that uses the youtubeInMp3 API. Everything works as it should when downloading mp3 files using the API however it doesn't work for all videos, I'm not sure which videos give the issue, I've noticed that it often happens when the YouTube video ID contains the _ character. when it does I get the below error... I know that the issue isn't with the video as it works when I test it http://www.youtubeinmp3.com I've tried urlEncoding the id before passing it to the API, replacing _ with - and replacing _ with %20 with no success. Any idea what might be going wrong here/how I can go about fixing it?
My error (from chrome developer console)
core.es5.js:3046 Angular is running in the development mode. Call
enableProdMode() to enable the production mode.
main.bundle.js:368 id: t0sS60Jx51c main.bundle.js:788 url
main.bundle.js:789
http://www.youtubeinmp3.com/fetch/?format=JSON&video=https://www.youtube.com/watch?v=t0sS60Jx51c
main.bundle.js:376 SyntaxError: Unexpected token < in JSON at position
0
at Object.parse ()
at Response.Body.json (vendor.bundle.js:37736)
at MapSubscriber.project (main.bundle.js:791)
at MapSubscriber._next (vendor.bundle.js:22171)
at MapSubscriber.Subscriber.next (vendor.bundle.js:242)
at XMLHttpRequest.onLoad (vendor.bundle.js:38165)
at ZoneDelegate.webpackJsonp.576.ZoneDelegate.invokeTask (polyfills.bundle.js:2496)
at Object.onInvokeTask (vendor.bundle.js:5501)
at ZoneDelegate.webpackJsonp.576.ZoneDelegate.invokeTask (polyfills.bundle.js:2495)
at Zone.webpackJsonp.576.Zone.runTask (polyfills.bundle.js:2263)
When I make this request that gives me an error in the insomnia REST client I get the following response:
metahttp-equiv="refresh" content="0" url="http://www.youtubeinmp3.com/download/?video=https://www.youtube.com/watch?v=t0sS60Jx51cautostart=1n=x="
An example of a response successful request to the youtubeInMp3 Api, the id logged in the console is the YouTube video id:
id: bjLorSJAB70 main.bundle.js:788 url main.bundle.js:789
http://www.youtubeinmp3.com/fetch/?format=JSON&video=https://www.youtube.com/watch?v=bjLorSJAB70
main.bundle.js:371 Objectlength: "199"link:
"http://www.youtubeinmp3.com/download/get/?i=fOzuoPTm06oBoLw3aidWejXF7Yc2JB3T&e=33"title:
"Santo Daime EU CHAMO A CURA"proto: Object main.bundle.js:373
http://www.youtubeinmp3.com/download/get/?i=fOzuoPTm06oBoLw3aidWejXF7Yc2JB3T&e=33
My code:
//function that passes the video id to a restService for downloading:
download(id: string) {
console.log("id: " + id);
this.restService.yDownload(id)
.subscribe(
(res) => {
console.log(res);
let url = res.link;
console.log(url);
window.location.href = `${url}target="_blank"`;
}, (res) => {
console.log(res)
});
}
//rest service function for getting the download link from youtubeInMp3 api
yDownload(id: string) : Observable<any> {
let params = [
`format=JSON`,
`video=https://www.youtube.com/watch?v=${id}`
].join('&');
let queryUrl = `${this.Y_DOWNLOAD_URL}?${params}`;
console.log("url");
console.log(queryUrl);
return this.http.get(queryUrl)
.map((res: Response) => res.json())
.catch((err: any) => Observable.throw(err || 'server error'));
}
I've been using DotNetOpenAuth 3.5.0.10357 successfully for the last 2 years and TODAY I'm getting "Failed to obtain access token. Authorization Server reports reason: (unknown)" while processing facebook response.
Any ideas? Has facebook changed something today? Anyone having same issues?
public ActionResult FacebookResponse(string returnUrl)
{
IAuthorizationState authorization = facebookClient.ProcessUserAuthorization();
if (authorization == null)
{
throw new Exception("No authorization from Facebook!");
}
else
{
var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
Error is on facebookClient.ProcessUserAuthorization();
Thanks
I am new to titanium appcelerator family. Also I am not sure if somebody has posted the same problem before. I couldn't found it so posting it here.
I am developing one mobile application. And in my application I am trying to call one web service which is hosted on my local environment, but it is always returning response with status code 0 and error message "Can't reach host". So I thought that there should be some problem with my web service that I deployed on remote location. And hence I have tried to call some other web services like twitter, but it's same.. :( It is giving me an error while calling twitter web service also.
I also check for a cross domain policy issue. So I have also tried to set rule on server for web service, but it didn't work out. Following is code snippet and environment details that I am using.
Application type: Mobile
Titanium SDK: 2.1.4 GA
Device: Web Browser
Host Operating System: Windows 7
Titanium Studio: Titanium Studio, build: 2.1.2.201208301612
Files for sample web service which is I am calling is present on following locations:
http://db.tt/XoSCujux (api.php)
http://db.tt/bJG2A5XT (Rest.inc.php)
http://db.tt/Hxt6Oojx (.htaccess)
Code:
//declare the http client object
var xhr = Titanium.Network.createHTTPClient();
//this method will process the remote data
xhr.onload = function() {
//check to see if we are refreshing the data via our
//pull and release mechanism
//create a json object using the JSON.PARSE function
result = JSON.parse(this.responseText);
Ti.API.info(result);
console.log(result);
var msgTitle = "data:";
var msgText = result;
var alertBox = Ti.UI.createAlertDialog({
title: msgTitle,
message: msgText
});
alertBox.show();
};
//this method will fire if there's an error in accessing the remote data
xhr.onerror = function(e) {
//log the error to our titanium developer console
Ti.API.error(this.status + ' - ' + this.statusText);
console.log(this.status + ' - ' + this.statusText);
var msgTitle = "Error : " + this.status;
var msgText = "Error Text : " + this.statusText;
var alertBox = Ti.UI.createAlertDialog({
title: msgTitle,
message: msgText
});
alertBox.show();
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT: " + this.responseText);
Ti.API.debug("ERROR: " + e.error);
alert('There was an error retrieving the remote data. Try again.' + e.error);
};
//open up the recipes xml feed
xhr.open("POST", "http://127.0.0.1/rest_example/api.php?rquest=locations");
//finally, execute the call to the remote feed
xhr.send();
Any help would be really appreciated.
I've recently started having trouble logging into my site using Facebook. I keep seeing this error message:
Facebook.FacebookOAuthException: (OAuthException) Error validating verification code.
There have been significant changes to the site and software; before I dig in to the changes, I'd like to eliminate some of the simple, common causes.
Could this be a firewall issue (the site is behind a firewall and not accessible from outside our network)? What are the most common causes for this error message?
Make sure your redirectUri parameter is the same as the redirecturi you used on https://www.facebook.com/dialog/oauth call.
For example, given an initial authentication request
using Facebook;
public ActionResult fbLogOn( string token, string returnUrl )
{
var oAuthClient = new FacebookOAuthClient( FacebookApplication.Current );
oAuthClient.RedirectUri =
new Uri( "http://" + "localhost:3434" + "/Home/fbOAuth" );
<... etc ...>
Make sure the handler for the facebook response sets the redirect URI to the exact same URI:
using Facebook;
public ActionResult fbOAuth(string code, string state )
{
FacebookOAuthResult oauthResult;
if (FacebookOAuthResult.TryParse( Request.Url, out oauthResult ))
{
string token = HttpUtility.UrlDecode( state );
if (oauthResult.IsSuccess)
{
var oAuthClient = new FacebookOAuthClient( FacebookApplication.Current );
oAuthClient.RedirectUri =
new Uri( "http://" + "localhost:3434" + "/Home/fbOAuth" );
dynamic tokenResult = oAuthClient.ExchangeCodeForAccessToken( code );
string accessToken = tokenResult.access_token;
<... etc ...>