extended permission publish_actions - javascript

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.

Related

submitLoginForm() does not send the data to the authentication server - MobileFirst Cordova client

I am trying to write a cordova hybrid application test application on MobileFirst platform. In my challenge handler, I have included a code to send a login information to my authentication server using submitLoginForm() java script API.
I check using wireshark if any auth request to my authentication server is getting generated, but it does not.
Can you please help me identify the issue with my code?
I can see the alert until Inside handleChallenge3, but does not see the alert for Closing Challenge Handler.
One more thing, I am trying to use isCustomResponse() API just to see what kind of challenge/response is coming to my challenge handler, but it seems not to be getting triggered. Has this been deprecated in MobileFirst Platform 8?
Thanks
var LtpaAuthChallengeHandler = function(){
LtpaAuthChallengeHandler = WL.Client.createWLChallengeHandler("LtpaBasedSSO");
LtpaAuthChallengeHandler.isCustomResponse = function(transport) {
alert ("Inside isCustomResponse");
return true;
};
LtpaAuthChallengeHandler.loginResponse = function(response) {
alert ("Inside loginResponse");
LtpaAuthChallengeHandler.submitSuccess();
alert ("After loginResponse");
};
// handleFailure
LtpaAuthChallengeHandler.handleFailure = function(error) {
// WL.Logger.debug("Challenge Handler Failure!");
if(error.failure !== null && error.failure !== undefined){
alert(error.failure);
}
else {
alert("Unknown error");
}
};
LtpaAuthChallengeHandler.handleChallenge = function(challenge) {
alert ("Inside handleChallenge");
var msg = "";
alert ("Inside handleChallenge1");
var options = {
"headers" : {},
"parameters" : {
"username" : "admin",
"password" : "admin",
'login-form-type' : 'pwd'
}
};
alert ("Inside handleChallenge2");
var loginUrl = "<URI for forms based auth of auth server>";
alert ("Inside handleChallenge3");
LtpaAuthChallengeHandler.submitLoginForm (loginUrl, options, LtpaAuthChallengeHandler.loginResponse);
alert ("Closing Challenge Handler");
};
};
Once the credentials have been collected from the UI, use WLChallengeHandler's submitChallengeAnswer() to send an answer back to the security check.
isCustomResponse() is not applicable from MFP 8.0.
Refer to the Authentication and Security topic here.

Parse.com on Signup User name already exists, code 142

Update: Solved, happens to be incorrect Cloud Code I wrote, see update #3
I am trying to make a signup for user using Parse.com API in Javascript.
Still with no success.
Basically I have a user field and a password field, and when hit signup button, tries to login but always I have the "Error Code: 142 :User name already exists, try login error from Parse api.
What is wrong with the code? (I previously used c# code and it was success)
Thanks in response.
function onSignupButtonClicked(button) {
event.preventDefault();
game_username = $("#loginUserText").val();
game_password = $("#loginPasswordText").val();
parseLogout(); // tried both logout earlier or put here..
var user = new Parse.User();
user.set("username", game_username);
user.set("password", game_password);
var progressCircle = showProgressCircle(); //some fullscreen progress
//also tried user.signup(null, {.. with no luck
Parse.User.signUp(game_username, game_password, {}, {
success: function(user) {
// Hooray! Let them use the app now.
//NOW LOGIN
login(game_username, game_password).then(function(result) {
console.log(result); // "Stuff worked!"
hideProgressCircle(progressCircle);
$("#loginButton").attr("disabled", true);
$("#logoutButton").attr("disabled", false);
$("#signupButton").attr("disabled", true);
game_manualLogin = true;
isLoggedIn = true;
}, function(err) {
hideProgressCircle(progressCircle);
console.log("loginPromise: " + err.message + " code: " + err.code); // Error: "It broke"
handleParseError(err);
});
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
hideProgressCircle(progressCircle);
handleParseError(error);
}
});
}
update:
Even basic Parse.com javascript returns 142.. here is the code, and my location is Istanbul/Turkey
function register() {
var user = new Parse.User();
user.set("username", "testop");
user.set("password", "testop");
user.set("email", "email#example.com");
// other fields can be set just like with Parse.Object
user.set("phone", "415-392-0202");
user.signUp(null, {
success: function(user) {
// Hooray! Let them use the app now.
console.log("testop register ok!");
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
}
});
}
This is the error I get to above updated code
Error:code: 142 :User name already exists, try login (Code is from Parse Javascript Signup
Update #2:
Even Rest API gives same error:
MacBook-Pro:~ gg$ curl -X POST \
> -H "X-Parse-Application-Id: MYAPPID" \
> -H "X-Parse-REST-API-Key: MYRESTAPIKET" \
> -H "X-Parse-Revocable-Session: 1" \
> -H "Content-Type: application/json" \
> -d '{"username":"testdude","password":"tesdude","phone":"415-392-0202"}' \
> https://api.parse.com/1/users
{"code":142,"error":"User name already exists, try login"}
MacBook-Pro:~ gg$
UPDATE #3:
After checking with 3 apis, found that problem was my fault.
I forgot a Cloud Code on user save, which was faulty as it did not check length of query length..
Parse.Cloud.beforeSave(Parse.User, function(request, response) {
var username = request.object.get("username");
var usernamequery = new Parse.Query(Parse.User);
usernamequery.equalTo("username", username);
usernamequery.find({
success: function()
{
--->>>should be checking length of query here <<<---
console.log("same user name found");
response.error("User name already exists, try login");
},
error: function(error)
{
console.log("ok unique user name continue save");
response.success("OK saving user");
}
});
});
You need two forms, one for signing up (as a new user) which calls Parse.User.signUp and a second form (for returning users) that calls Parse.User.logIn.
The problem is that you can only 'sign up' once with a username and password, after which you should 'login'. Also when you have got a success callback from Parse.User.signUp then the user is logged in and you don't have to call 'login'.
Something like this (where the two event listeners are triggered by two different buttons).
SIGNUP
function onSignupButtonClicked(button) {
event.preventDefault();
game_username = $("#loginUserText").val();
game_password = $("#loginPasswordText").val();
Parse.User.signUp(game_username, game_password, {}, {
success: function(user) {
// A new user has signed up and is now the Parse.User.current() user
// Do something
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
}
});
}
LOGIN
function onLoginButtonClicked(button) {
event.preventDefault();
game_username = $("#loginUserText").val();
game_password = $("#loginPasswordText").val();
Parse.User.logIn(game_username, game_password, {}, {
success: function(user) {
// An existing user has logged in and is now the Parse.User.current() user
// Do something
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
}
});
}
More info here: https://parse.com/docs/js_guide#users-signup

Check if user liked my FB page on my external website

I know, that there are lot of questions with this error, but still I can't find solution for this error:
Given URL is not permitted by the application configuration.: One or
more of the given URLs is not allowed by the App's settings. It must
match the Website URL or Canvas URL, or the domain must be a subdomain
of one of the App's domains.
I'm working with this example:
$(document).ready(function() {
FB.login(function(response) {
if (response.status == 'connected') {
var user_id = response.authResponse.userID;
var page_id = "383152115092391"; //"383152115092391"; // coca cola page https://www.facebook.com/cocacola
var fql_query = "SELECT uid FROM page_fan WHERE page_id=" + page_id + " and uid=" + user_id;
FB.api('/me/likes/'+page_id, function(response) {
if (response.data[0]) {
$("#container_like").show();
} else {
$("#container_notlike").show();
}
});
} else {
// user is not logged in
}
});
});
jsfiddle example
And this is my DB app configuration:
basic settings
advanced settings
Can you please tell me, what am I missing?

facebook javascript api post photo via chrome needs refresh

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

Facebook Javascript, How to detect if user is a fan of my facebook page? While on my site?

I have the following JS code.
The code's purpose is to first get the users facebook id, and then using FQL check that id against my page ID and make sure the user is a fan.
The problem I am running into is that the only time the code actually works is if i login with my own personal facebook profile. I think its because my profile and the FB.init appid are somehow linked?
Can someone take a look at this code and show me where I am going wrong?
My goal again is to use JS to first get the users id (thus their thumbnail image), and then cross reference that against my own facebook page to check and see if they are a fan. If they are a facebook fan, then I will probably give them a coupon or something.
Thanks in advance.
<script src="http://connect.facebook.net/en_US/all.js"></script>
//Connect to facebook with my app id..
FB.init({
appId:'135445813195028',
cookie:false,
status:true,
xfbml:true
});
//Check to see if user is actually CONNECTED???
FB.getLoginStatus(function(response) {
if (response.session) {
// USER IS CONNECTED
FB.api('/me', function(user) {
if (user != null) {
var image = document.getElementById('imagez');
image.src = 'http://graph.facebook.com/' + user.id + '/picture?type=large';
var name = document.getElementById('name');
name.innerHTML = user.name;
FBID = user.id;
console.log('Facebook ID:' + FBID);
//assemble an FQL query to see if the guy is a fan of our page...
myquery = 'SELECT uid FROM page_fan WHERE page_id = 126923080686340 AND uid = ' + FBID;
console.log('query = ' + myquery);
///Run FQL Query to see if user is a fan
FB.api({
method: 'fql.query',
query: myquery
}, function(resp) {
if (resp.length) {
var IsFan = true;
alert('You are A fan!')
console.log('Visitor is a fan');
//show coupon code...
} else {
alert('Signed into facebook, but Not a fan!');
var IsFan = false;
console.log('Visitor is not a fan');
//show like button...
//once like is clicked then refresh the page...
}
});
//END Run FQL Query to see if user is a fan
}
});
//Figure out if they are a fan...
} else {
// USER IS NOT CONNECTED
alert('NO USER session, user is not logged into facebook!!!');
}
});
The FB.getLoginStatus check to see if the user is connected to your application .. not to facebook.
But when the user is not connected to your application, the .status property can tell you the reason of the fail (if the user is not logged-in at all, or just to your app).
So the structure you should use is
FB.getLoginStatus(function(response) {
if(response.session) {
alert('connected to Application');
} else {
// no user session available, someone you dont know
if(response.status == "notConnected") {
// But user is logged into facebook
alert("Not connected to Application, but is logged in to Facebook");
} else {
// User is not logged into facebook
alert('Not logged in to facebook');
}
}
});
But you cannot access the ID of a user that has not authorized your Application.
Not through Javascript API.

Categories