Image uploaded to Facebook but not shown on page - ios

I am trying to upload an image to a specific album on Facebook page through Graph api call from ipad app. Everything is working correctly and the response from Facebook returns success with the id of post but I just can't see the image uploaded on the page. I am doing this using Appcelerator Titanium. Following is my code:
var fb = require('facebook');
fb.appid = 'MY APP ID';
fb.permissions = ['read_stream'];
function postImageToFb(){
fb.reauthorize(['publish_actions','manage_pages'], 'me', function(e){
if (e.success) {
// If successful, proceed with a publish call
var data = {
source: Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory+'/image.png').read(),
message: 'Hello pic'
}
fb.requestWithGraphPath('<album-id>/photos',data,'POST',function(e){
alert('Post to fb: '+JSON.stringify(e));
if(e.success){
alert('Photo submitted successfully to fb.')
}else{
alert('Failed to upload photo to fb: ')
}
})
} else {
if (e.error) {
alert(e.error);
} else {
alert("Unknown result");
}
}
});
}
$.btn_submit.addEventListener('click',function(e){
if(fb.loggedIn){
postImageToFb();
}else{
fb.authorize();
fb.addEventListener('login',function(e){
if(e.success){
postImageToFb();
}else{
alert('Failed to login fb: ',e);
}
})
}
})
I have used the same account for creating Facebook app, page and Facebook login from app so it shouldn't be the problem. What might be the problem? Can someone help me. Thanks.

I could never get the requestWithGraphPath() to work with a page, even with the access token FOR the page. It would always post to the Pages wall, but as my personal profile.
See how I ended up doing it here (underneath the profile explanation is an explanation on Pages): https://stackoverflow.com/a/28144909/4121164

Related

facebook redirect url not redirecting to intended url from facebook app

I have FB.init function to share on facebook. I am able to redirect to given redirect url through other browsers. But the same thing is not working on facebook app. It redirects me to the home url.
My function is defined as,
FB.ui({
method: 'share',
display: 'iframe',
href: "http://XX.XX.XXX.XXX:XXXX/vacation_builders/" + vb_id,
picture: imageurl,
description: blog_description,
title: blog_title
},
function(response) {
console.log(response);
if (response && !response.error_message) {
console.log(response.status);
window.location = '/congrats'
}
else if (response && !response.error_message == "User canceled the Dialog flow") {
self.location.href = '/congrats'
}
else if (response && !response.error_message == "User+canceled+the+Dialog+flow") {
self.location.href = '/congrats'
}
});
After i'm done sharing this image with url :- http://XX.XX.XXX.XXX:XXXX/vacation_builders/" + vb_id.
when I go to facebook and click on the image then everything works fine whether I click from facebook logged in from mobile browser or desktop browsers but when i go to facebook app and clicks on the link then it takes me to http://XX.XX.XXX.XXX:XXXX instead of http://XX.XX.XXX.XXX:XXXX/vacation_builders/" + vb_id.

Sharing Emoji to Twitter feed with Appcelerator

I have been using this method (https://github.com/ebryn/twitter-titanium) of authenticating with Twitter for a while now. I am currently using Ti Studio 4.2.0.201508141038, Ti SDK 3.5.1. I know this is a little old but I am on this version for support reasons.
I am trying to allow the sharing of text entered in a TextArea to twitter including emojis. For some reason sharing to Facebook works like a charm but twitter I receive "����". Please note that I have only tested iOS to date. Android will follow.
Is there some encoding method that I should be using that will get me through this?
The code I am using to post is simply as follows:
var Twitter = require('twitter').Twitter;
var client = Twitter({
consumerKey: consumerKey,
consumerSecret: consumerSecret,
accessTokenKey: accessTokenKey,
accessTokenSecret: accessTokenSecret
});
client.addEventListener('login', function(e) {
if (e.success) {
Ti.App.Properties.setString('twitterAccessTokenKey', e.accessTokenKey);
Ti.App.Properties.setString('twitterAccessTokenSecret', e.accessTokenSecret);
var tweet = textArea.value.replace(/[\n\r]/g, '');
client.request("1.1/statuses/update.json", {status: tweet, trim_user:'t'}, 'POST', function(e) {
if (e.success) {
console.log('success');
} else {
console.log('Twitter Post failed.\nDetail is:'+JSON.stringify(e.data));
}
});
} else {
Ti.API.debug(JSON.stringify(e));
}
});
client.authorize();
Funnily, I found that if I make tweet equal to:
var tweet = textArea.value.replace(/[\n\r]/g, '') + '\ue415';
I do get a smiley in my tweet but only on my device not on twitter.com. But if I type that code directly into my TextArea it gets tweeted verbatum.
I have also tried using encode(tweet) and urlEncode(tweet) but they really don't work.
Is there a way I can get emojis tranlated into text that will then post correctly on twitter?

Cordova/Ionic Facebook getLoginStatus not working

I am developing an App in Ionic/Cordova with Login over Facebook. Before showing the "Login-Page" I would like to check if the user is already connected.
The following getLoginStatus check works as expected in the iOS Simulator. When testing on the actual device, the getLoginStatus callback does not get fired.
facebookConnectPlugin.getLoginStatus(
function (response) {
if (response.status == "connected") {
set_tokens(response);
$location.path('/tab/person/me/events');
}
},
function (response) { alert(JSON.stringify(response)) }
);
Already set the Facebook-App to public and verified the App-Id.
Can anybody give a reason for the described behaviour?
I have the following implementation for Facebook login using facebookConnect Plugin.
facebookConnectPlugin.getLoginStatus(
function(response){
if(response.status == "connected"){
//do something, for example share or redirect
}else{
facebookConnectPlugin.login(["basic_info"],
function(success) { /*do something...*/},
function(error) {
//handle error
});
}
}, function(error) {
// handle error
})
}
If you still have errors, try to log the error and success events to see what is happening. This implementations works in a controller.

Error in FB.login() phonegap facebook plugin

When i run fb.login() in an ios 6 device using the account setted in Settings/facebook i get the following
operation couldn't be completed (com.facebook.sdk error 2)
in ios 5 the app works perfectly, the problem is the native login
help please ! this is my code
this is the facebook init
this.appId = appId;
var me = this;
document.addEventListener('deviceready', function() {
try {
FB.init({ appId: "294003447379425", status: true, cookie: true, nativeInterface: CDV.FB, useCachedDialogs: false });
} catch (e) {
console.log(e);
}
}, false);
if (!this.appId) {
Ext.Logger.error('No Facebook Application ID set.');
return;
}
var me = this;
me.hasCheckedStatus = false;
FB.Event.subscribe('auth.logout', function() {
// This event can be fired as soon as the page loads which may cause undesired behaviour, so we wait
// until after we've specifically checked the login status.
if (me.hasCheckedStatus) {
me.fireEvent('logout');
}
});
// Get the user login status from Facebook.
FB.getLoginStatus(function(response) {
me.fireEvent('loginStatus');
clearTimeout(me.fbLoginTimeout);
me.hasCheckedStatus = true;
if (response.status == 'connected') {
me.fireEvent('connected');
Ext.Viewport.add(Ext.create('CinePass.view.Main'));
} else {
me.fireEvent('unauthorized');
console.log('noconectado');
Ext.Viewport.add(Ext.create('CinePass.view.LoggedOut'));
}
});
// We set a timeout in case there is no response from the Facebook `init` method. This often happens if the
// Facebook application is incorrectly configured (for example if the browser URL does not match the one
// configured on the Facebook app.)
me.fbLoginTimeout = setTimeout(function() {
me.fireEvent('loginStatus');
me.fireEvent('exception', {
type: 'timeout',
msg: 'The request to Facebook timed out.'
});
Ext.Msg.alert('CinePass', 'Existe un problema con Facebook, se iniciará la aplicación sin conexión a Facebook.', Ext.emptyFn);
Ext.Viewport.add(Ext.create('CinePass.view.Main'));
}, me.fbTimeout);
this is the login
FB.login(
function(response) {
if (response.session) {
alert(response.session);
} else {
alert(response.session);
}
},
{ scope: "email,user_about_me,user_activities,user_birthday,user_hometown,user_interests,user_likes,user_location,friends_interests" }
);
Having the same problem and took me few days to figure this out, there are a number of reasons:
1) The first time you launch your app, if you deny the "Do you allow this app to use your facebook permission", you'll get this error, what you need to do is, go to Setting > General > Facebook > turn on your app OR go to Setting > General > Reset > Reset Location & Privacy (this will reset and ask you the "Do you allow this app to use your facebook permission" again for all app.
2) Slow/No Internet can caused the error
3) Create your certificate again, and go to build.phonegap.com, create a new key for IOS and change the IOS key (This works for me, I have no idea how it works but it does, I notice a significant app file size increase after i use a new IOS Key)
4) If your app is in sand box mode, and your IOS current Facebook account is not an app tester you'll get the error too. I just disable the sand box mode and it works, make sure your Facebook App Setting has the correct bundle ID, if your app is still under developement, put 0 to app store ID.

FB redirect issue with white page in iOS chrome

When I press the login button I get the facebook page where I have to give permission to use my facebook account.
After I give permission, it redirects to https://www.facebook.com/dialog/permissions.request and a blank page is shown. On Android the "window.FB.login" callback is called (see code below) where I can get the info and redirect the user but on Windows Phone it only shows that blank page. When I go to my facebook page, my site is registered in the app list. So the registration did work correctly.
This error has been caused due to unsafe loading of facebook js file.
For integrating Facebook app in your application you have to follow the steps instructed in Facebook app documentation.
var fbApi = {
init: function () {
$.getScript(document.location.protocol + '//connect.facebook.net/en_US/all.js', function () {
if (window.FB) {
window.FB.init({
appId: MY_APP_ID,
status: true,
cookie: true,
xfbml: false,
oauth: true,
channelUrl: 'http://www.yourdomain.com/channel.html'
});
}
});
},
login: function () {
/// <summary>
/// Login facebook button clicked
/// </summary>
log("login facebook button clicked");
if (window.FB) {
//Windows phone does not enter this method, Android and Iphone do
window.FB.login(function (response) {
if (response.status) {
log('it means the user has allowed to communicate with facebook');
fbAccessToken = response.authResponse.accessToken;
window.FB.api('/me', function (response) {
//get information of the facebook user.
loginService.subscribeSocialUser(response.id, response.first_name, response.last_name, fbAccessToken, "", "FaceBook", fbSucces, fbFail);
});
} else {
log('User cancelled login or did not fully authorize.');
}
},
{ scope: 'email'
});
}
}
};
channel URL is added so as to resolve any cross browser issues.
It should point to an html file which refers to the js as follows:
<script src="//connect.facebook.net/en_US/all.js"></script>
If once an error has been hit while initializing Facebook.js, you will not be able to login successfully.
You can load java script either synchronously or asynchronously.
(function(d, debug){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));

Resources