How can i connect facebook and update status - facebook-graph-api

I have examined Facebook Modul on this link
I would like to post message to facebook but I don't connect facebook with below code on Android and iOS simulator too.
var fb = require('facebook');
fb.appid = "55xxxxxxxxxx";
fb.permissions = ['publish_stream'];
// Permissions your app needs
fb.authorize();
fb.requestWithGraphPath('me/feed', {message: "Trying out FB Graph API and it's fun!"},
"POST", function(e) {
if (e.success) {
alert("Success! From FB: " + e.result);
} else {
if (e.error) {
alert(e.error);
} else {
alert("Unkown result");
}
}
});
I have just created an app on Facebook's http://developer.facebook.com page
Should i use Add Platform button on Facebook Developer setting tab?
If answer is yes. How can i fill
Facebook Plaform's iOS Bundle ID iPhone Store ID iPad Store ID
Facebook Plaform's Android Package Name Class Name Key Hashes
My app is not published on market. It is test case yet.
My Titanium SDK is 3.2.3GA and i am testing it on iOS 7.1 simulator
Thank you in advance.

Try to set an event listener to facebook login event like this :
var fb = require('facebook');
fb.appid = "55xxxxxxxxxx";
fb.permissions = ['publish_stream'];
// Permissions your app needs
fb.authorize();
fb.addEventListener("login", function(e) {
if (e.success) {
fb.requestWithGraphPath('me/feed', {
message : "Trying out FB Graph API and it's fun!"
}, "POST", function(e) {
if (e.success) {
alert("Success! From FB: " + e.result);
} else {
if (e.error) {
alert(e.error);
} else {
alert("Unkown result");
}
}
});
} else {
if (e.error) {
alert(e.error);
} else {
alert("Unkown result");
}
}
});

Related

Expo Google Authentication doesn't work on production

I implemented Expo Authentication on my app, following the code from the doc https://docs.expo.io/guides/authentication/#google.
On local with the Expo client its working fine, in the IOS simulator and also in the web browser but when I build the app (expo build android) and try on my Android phone, the Google popup comes, I put my id and it send me back to the login page but NOTHING happen.
I put some alert to understand what was going on but I dont even get any, useEffect doesn't fire, responseGoogle doesnt seem to change.
const [requestGoogle, responseGoogle, promptAsyncGoogle] =
Google.useAuthRequest({
expoClientId:
"my_id",
androidClientId:
"my_id,
webClientId:
"my_id",
});
useEffect(() => {
alert("useEffect fired (Google)");
if (responseGoogle?.type === "success") {
const { authentication } = responseGoogle;
// success
alert("success : "+JSON.stringify(responseGoogle));
// some code to check and log the user...
} else {
alert('no success : '+JSON.stringify(responseGoogle));
}
}, [responseGoogle]);
Any idea ?
Apparently its a know bug so here is not the answer but an alternative with expo-google-sign-in :
import * as GoogleSignIn from "expo-google-sign-in";
async function loginWithGoogle() {
try {
await GoogleSignIn.askForPlayServicesAsync();
const { type, user } = await GoogleSignIn.signInAsync();
if (type === "success") {
alert(JSON.stringify(user));
}
} catch ({ message }) {
toast.show("Erreur:" + message);
alert("login: Error:" + message);
}
}

How to fix "Error unmarshalling response back from AWS, Response Body: Unknown error" in x.io using Unity AWS SDK for DynamoDB

I developed DynamoDB Tables for my application using unity SDK. Authentication is done using Cognito identities. When trying to read/write values to a table it is working in my local machine. But when the application is hosted in x.io I get an error.
I am not able to figure out the issue. There are not many resources to debug this error.
public void PostUserAccountDetails(UserAccounts userInfo)
{
DbContext.LoadAsync<UserAccounts>(userInfo.mailID, (result) =>
{
if (result.Exception == null)
{
var user = result.Result as UserAccounts;
Debug.Log(user == null ? true : false);
if (user == null)
{
Debug.Log("mail id is new");
signupText.text = "The mail id has never been used before";
DbContext.SaveAsync<UserAccounts>(userInfo, (res) =>
{
if (res.Exception == null)
{
Debug.Log("signed up successfully");
signupText.text = "signed up successfully";
}
else
{
Debug.Log("error while signing up");
signupText.text = "error while signing up";
}
});
}
else
{
Debug.Log("This mail id has already been used");
signupText.text = "This mail id has already been used";
}
}
else
{
Debug.Log(result.Exception.Message);
signupText.text = result.Exception.Message;
}
});
}
I get the error message
"Error unmarshalling response back from AWS, Response Body: Unknown error"

Ballerina Facebook Connector - Unable to create a facebook client

I am using ballerina facebook connector. I have configured the following in my code. The access token is retrieved through facebook Graph API explorer v3.2.
import ballerina/io;
import wso2/facebook;
import ballerina/http;
facebook:FacebookConfiguration facebookConfig = {
clientConfig:{
auth:{
scheme: http:OAUTH2,
accessToken:"AccessTokenRetrieved"
}
}
};
function getPageAccessTokens(facebook:Client facebookclient) {
io:println("-----------------Requesting page access token------------------");
var response = facebookclient->getPageAccessTokens("userid");
}
public function main(){
facebook:Client facebookclient = new(facebookConfig);
getPageAccessTokens(facebookclient);
}
The code is compiling but the facebookclient is empty. But when I directly call the facebook endponit a facebook client is successfully created.
public function main(){
http:Client clientEP = new("https://graph.facebook.com/pageid?fields=access_token&access_token=AccessTokenRetrieved");
var resp = clientEP->get("");
if (resp is http:Response) {
var payload = resp.getTextPayload();
if (payload is string) {
io:println(payload);
} else {
io:println(<string> payload.detail().message);
}
} else {
io:println(<string> resp.detail().message);
}
}
What is wrong in my first implementation that use ballerina facebook connector?

Facebook Login Button: Workaround for bug of Chrome on iOS

Currently, I am trying to solve a bug logged in Facebook Developer:
https://developers.facebook.com/bugs/325086340912814/
I am using ASP.NET MVC 3 with Facebook C# SDK and Facebook Javascript SDK.
Here is javascript code:
window.fbAsyncInit = function () {
// init the FB JS SDK
FB.init({
appId: '298365513556623', // App ID from the App Dashboard
channelUrl: 'http://www.christianinfoportal.com/channel.html', // Channel File for x-domain communication
status: true, // check the login status upon init?
cookie: true, // set sessions cookies to allow your server to access the session?
xfbml: true // parse XFBML tags on this page?
});
// Additional initialization code such as adding Event Listeners goes here
FB.Event.subscribe('auth.authResponseChange', function (response) {
if ((response.status == 'connected')) {
if (fbIgnoreFirstEventFire)
fbIgnoreFirstEventFire = false;
else {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
// TODO: Handle the access token
// Do a post to the server to finish the logon
// This is a form post since we don't want to use AJAX
var form = document.createElement("form");
form.setAttribute("method", 'post');
form.setAttribute("action", '/FBLogin');
var field = document.createElement("input");
field.setAttribute("type", "hidden");
field.setAttribute("name", 'accessToken');
field.setAttribute("value", accessToken);
form.appendChild(field);
var field = document.createElement("input");
field.setAttribute("type", "hidden");
field.setAttribute("name", 'returnUrl');
field.setAttribute("value", window.location.href);
form.appendChild(field);
document.body.appendChild(form);
form.submit();
}
} else if (response.status == 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
};
// Load the SDK's source 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));
The View code is pretty simple:
<div id="fbLoginButton" class="fb-login-button" data-show-faces="false" data-width="50" data-max-rows="1" data-scope="email"></div>
I basically forward the access token to a server side code page:
public ActionResult FBLogin(String returnUrl)
{
var accessToken = Request["accessToken"];
//FB fires even without the user clicking the Log In button
Session["FBLoginFirstClick"] = true;
//Session["AccessToken"] = accessToken;
//this.lblAccessToken.Text = accessToken;
//Response.Redirect("/MyUrlHere");
var client = new Facebook.FacebookClient(accessToken);
dynamic me = client.Get("me");
String email, fullName;
fullName = me.first_name + " " + me.last_name;
email = me.email;
Models.User.ThirdPartyLogin(email, fullName, Session);
if (!string.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
Solved by using Facebook authentication redirect.
https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/

FB.login cancel button do a redirect

currently i have a page under http://mydomain.com/me/myself/1234
on this page i've included a custom share link, to share information on this page to facebook.
imagine that you're not logged into facebook but in my application and you come to the above page. If you click on the link a FB login pop up appears to give you a chance to authenticate. my code for posting to the wall looks like this:
function loggedIn() {
if (typeof(FB) != 'undefined' && FB != null ) {
FB.login(function(response) {
if (response.session || response.authResponse) {
postToWall();
} else {
return false,
}
}, {scope: 'publish_stream'});
return false;
}
}
function postToWall() {
var prodName= 'test';
var prodPic = 'test.jpg';
var linkUrl = 'http://mydomain.com/me/myself/1234';
var tmpObj = new Object();
tmpObj.value = "CUSTOM";
tmpObj.friends = "ALL_FRIENDS";
var wallPost = {
message : " I've seen a " + prodName ,
picture : prodPic,
link: linkUrl,
name: "the name",
description: "a little description",
privacy: tmpObj
};
FB.api('/me/feed', 'post', wallPost , function(response) {
if (!response || response.error) {
//alert('Error occured');
} else {
//alert('Post ID: ' + response);
}
});
}
So, the only issue now is: if i click the cancel button on the login dialog, i get redirected to my .com page http://mydomain.com. what i need is to stay on the same page. I don't see the error i'm doing.
Would appreciate any help.
best regards,
Ramo
I don't understand why you have a function called loggedIn() calling a function called postToWall(). You might want to refactor or rename the loggedIn() function.
You did not post the event handler code for your button. However, if you are catching the click event but not returning false then not only will the facebook login window get shown, but the normal thing that occurs when you click on a link on a web page will also happen. That said, it doesn't sound like that's the problem but please post more code so that we may know for sure.