I'm trying to post photo on the client wall, it works great through Firefox, but when I'm trying doing the same through Chrome (or Explorer), the first time I'm using the application and install it, I don't get a response at all... When I'm refreshing the page and try again, it works fine and post the photo...
This is the code I'm using:
var imgURL = obj.picture;
FB.api('/me/photos', 'post', {
message: obj.description,
access_token: accessToken,
url: imgURL
}, function (responsePhoto) {
if (!responsePhoto || responsePhoto.error) {
if (!responsePhoto){
console.log(responsePhoto);
alert('An error has occured: please refresh and try again');
}
else {
console.log(responsePhoto);
alert('An error has occured:' + responsePhoto.error + ' please refresh and try again');
}
} else {
//alert('your photo has been uploaded');//('Post ID: ' + responsePhoto.id);
}
});
Any ideas?
Thanks
Related
After successfully log in, i try to get a few fields from the user.
All of them are undefined other than the name and ID. The pop up indeed ask those permission which I granted.
Read all posts here and non offered a solution that work other than using tokens(?) which I am not sure how, and never see in FB examples.
FB.login(
function(response) {
if (response.status === "connected") {
console.log("connected");
console.log("Access Token: " + response.authResponse.accessToken);
testAPI();
} else {
console.log("not connected");
}
},
{ scope: "email,user_age_range,user_friends" }
);
function testAPI() {
console.log("Welcome! Fetching your information.... ");
FB.api("/me", function(response) {
console.log("name: " + response.name);
console.log("email: " + response.email);
console.log("id: " + response.id);
console.log("friends: " + response.user_friends);
console.log("age: " + response.user_age_range);
console.log("end");
});
}
If I print response i get an error :
Uncaught ReferenceError: respond is not defined
To anyone who wonder, first, the way to read it is :
FB.api('/me', {fields: 'name,email'}, (response) => {
console.log('name: ' + response.name);
console.log('email: ' + response.email);
});
Second, a few points to notice:
Remove your app on your facebook profiles (under Apps) otherwise every time you test, FB will automatically grant access even if you wish to add more permissions.
Remove cache from your browser every new test because FB will keep the previous state and changes will not take effect.(sometimes, even updated deployments will not)
You should deploy your website, with me - local host is not working with FB because they require https.
Testing Facebook is a little bit hassle.
It is possible to embed a image in outlook email ? With this code outlook will insert a broken image mailBoxItem.body.setSelectedDataAsync
var linkToImage = '<img src=\"data:image/'+getTemplateExtension(template.templateType).replace('.','')+";base64," + sasLink + '\"/>';
//Add an image as a link
if (mailBoxItem.body.setSelectedDataAsync) {
mailBoxItem.body.setSelectedDataAsync(linkToImage, {
asyncContext: null,
coercionType: Office.CoercionType.Html
},
function(asyncResult) {
if (asyncResult.status == "failed") {
showMessage("Action failed with error: " + asyncResult.error.message);
} else {
showMessage("You successfully wrote in the email body. Click Next to learn more.");
}
}
)
}
It looks like currently outlook don't support inserting <img> tags which have a base64 encoded image in the src element, and requires you to have a full URL of the image instead.
So I wrote a server side script to which I am POSTing the base64 image string. The script saves the image on the server and then return's back the URL.Now finally you can create an <img> tag with the returned URL as src,and can be successfully embedded in the message body.
Used the followings code to get it working
var imageBase64Data = 'data:image/png;base64,iVBORw...';//truncated the actual base64 data as its too long
$.ajax({
type: 'post',
url: 'https://metalop.com/Word-Cloud-Generator/image-url-generator.php',
data: {
image: imageBase64Data
},
error: function(e) {
console.error(e);
},
success: function(response) {
console.log(response);
var imageHTML = "<img " +
"src='" + response + "' img/>";
console.log(imageHTML);
//Add an image as a link
Office.cast.item.toItemCompose(Office.context.mailbox.item).body.setSelectedDataAsync(imageHTML, {
coercionType: Office.CoercionType.Html,
},
function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
app.showNotification("Action failed with error: " + asyncResult.error.message);
}
});
}
});
I'm trying to do a get request with the javascript api to adobe reader. I'm using the Net.http object with the following code:
get = app.trustedFunction (function(cURL)
{
app.beginPriv();
var params =
{
cVerb: "GET",
cURL: "HTTP://ip_addr/checker/comments/1",
oHandler:
{
response: function(msg, uri, e)
{
if(e != undefined && e.error != 405) {
app.alert("Failed to get: "+ e);
} else app.alert("connected");
}
}
};
Net.HTTP.request(params);
app.endPriv();
});
When I call the function in my code, the first time the program opens its working fine and can connect.
The problem is that when I call the function again using a submenu like this:
app.addMenuItem ({cName: "connect", cParent: "Edit", cExec: "get()"});
I get an error, I also tried adding this PDF file to my privileged locations because I think it's a security related issue
Any idea?
Working on my first phonegap ios app.
Trying to incorporate this plugin https://github.com/Wizcorp/phonegap-facebook-plugin/tree/master/platforms/ios/www
Basically I just need to alert the users email and first/last name, although I'm a bit stuck on how to do so using this plugin.
What I wanted to do was retrieve that information, then pre populate some forms to create a new user to use with Parse.
I'm able to get a response from this function that displays a status and an authResponse with tokens and the user ID:
var login = function () {
if (!window.cordova) {
var appId = prompt("Enter FB Application ID", "");
facebookConnectPlugin.browserInit(appId);
}
facebookConnectPlugin.login( ["email"],
function (response) { alert(JSON.stringify(response)) },
function (response) { alert(JSON.stringify(response)) });
}
I'm just unsure in terms of next steps on how to go about retrieving the users email and first/lastname..and whther or not I have to dig deeper into facebooks API.
any help is appreciated.
* UPDATED *
Figured it out. I was missing a step that i found over at the facebook api page
var login = function() {
if (!window.cordova) {
facebookConnectPlugin.browserInit('APPID');
facebookConnectPlugin.browserInit(appId);
}
facebookConnectPlugin.login(["email"], function(response) {
if (response.authResponse) {
facebookConnectPlugin.api('/me', null,
function(response) {
alert('Good to see you, ' +
response.email + response.name + '.');
});
}
});
}
Try this plugin(http://plugins.cordova.io/#/package/com.ccsoft.plugin.cordovafacebook) this covers all of your needs.
I'm trying to post an action on user's timeline. I have 2 users, developer and normal user(not registred in app) and i can post on developer page but can't normal user
here my code
FB.api('/me/MYNAMESPACE:MYACTION?BYOBJECT=' + link, 'post',
function(response) {
var msg = 'Error occured';
if (!response || response.error) {
if (response.error) {
msg += '\n\nSomething wrong \n\n' + response.error.message;
}
alert(msg);
}
else {
alert('Done! Please check your activity log');
}
});
"link" is encoded url
sendbox mode is off and permition "publish_actions" in extended permissions is checked
If the action isn't approved you cannot post as a regular user. Only developers can do this.
Submit your action for approval.