How can I add the event_id parameter to my event? Please help!
First step should be reading documentation
My code to generate EventId looks like:
...
public static function getEventId()
{
return self::$eventId;
}
public static function setEventId(): void
{
self::$eventId = time().'.'.rand(1000000, 9999999);;
}
...
Event Id should be send in server event and same in pixel event
Example:
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq( 'init', '<?php echo FacebookCapiSettings::getPixelId(); ?>', {'external_id': '<?php echo $_COOKIE['USERID2']; ?>'<?php echo $userDataString; ?>} );
fbq( 'track', 'PageView', {}, {eventID: '<?php echo FacebookCapiPageView::getEventId(); ?>'} );
</script>
Related
starting with angular, i am trying to GET data from the server and then POST back modifications with $resources.
It's working fine except the "save" function. No Data is POSTed back to the server.
here is the html
<div ng-controller="myCtrl">
<div ng-repeat="obj in objs">
<h2>{{obj.data_1}}</h2>
<h3>{{obj.data_2}}</h3>
<input type='text' ng-model="obj.data_1"><br/>
<textarea ng-model="obj.data_2" required></textarea><br/>
<button ng-click="save()">Save</button>
</div>
</div>
service.js
'use strict';
angular.module('App.services', ['ngResource']).
factory('Obj', function($resource){
return $resource('url/to/json');
});
controller.js:
'use strict';
angular.module('App.controllers', []).
controller('myCtrl', ['$scope', 'Obj', function($scope, Obj) {
$scope.objs = Obj.query();
$scope.save = function() {
$scope.objs.save();
}
}]);
Do you know why nothing is POSTed back when i save ?
Using the query method on the $resource object implies return as follows 'query': {method:'GET', isArray:true} it's mean that your $scope.objs is an array of objects and not an object and depending on number of elements you can use the folowing notation:
$scope.objs[i].save()
where i is the index of element in the array, forexample if you have return like:
[ {id:1, name:'Some name', age:35} ];
then your code : $scope.objs[0].save()
Edit:
I have created a plunk, maybe it will help you... http://plnkr.co/edit/62iPCAUNjV0oJROhul1G
Shouldn't there be another $resource declared for POST the way it is declared for GET? Each $resource specify particular REST service.
//services.js
'use strict';
angular.module('App.services', ['ngResource'])
.factory('GetObj', function($resource){
return $resource('url/to/json');
}
.factory('SaveObj', function($resource){
return $resource('url/to/post');
});
//controller.js
'use strict';
angular.module('App.controllers', []).
controller('myCtrl', ['$scope', 'GetObj', 'SaveObj', function($scope, GetObj, SaveObj) {
$scope.objs = Obj.query();
$scope.save = SaveObj.save(objs, function(resp) {
//Callback
console.log("Response from POST: %j", resp);
}
}]);
In my application I want post a text message in facebook wall streemPublish but it is not working, can anyone tell me what i did wrong else guide me a good working tutorial,
also the below code does not showing any error....
Here is my code ...
<body>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript">
function publish() {
FB_RequireFeatures(["Connect"], function() {
FB.Facebook.init('113700398662301', 'xd_receiver.htm');
FB.ensureInit(function() {
var message = 'this is message';
var action_links = [{ 'text': 'Vote for Bill The Aircraft Carrier!', 'href': 'http://spayday.factor360.com/contest.html?page=viewInd&id=48082&contestId=2'}];
FB.Connect.streamPublish(message, action_links, null, "Share your support for Bill The Aircraft Carrier!", callback, false, null);
});
function callback(post_id, exception) {
alert('Wall Post Complete');
}
});
}
</script>
</body>
<p>Stream Publish Test</p>
Post a story
</html>
The code looks a little dated. Check this for updated info on stream publishing
https://developers.facebook.com/docs/reference/javascript/FB.ui/
and this for setting up your FB init.
https://developers.facebook.com/blog/post/525/
I am using facebook credits api and using its pay method, following is my code:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
'appId' : '<?php echo $app_id; ?>',
'session' : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it
'status' : true, // check login status
'cookie' : true, // enable cookies to allow the server to access the session
'xfbml' : true // parse XFBML
});
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
FB.Canvas.setAutoResize();
};
(function() {
FB_RequireFeatures(["CanvasUtil"], function() {
FB.CanvasClient.scrollTo(0, 0);
window.FB = null;
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
});
}());
</script>
<script type="text/javascript">
function placeOrder() {
var order_info = { "title":"Music Mood Points",
"description":"Get Music Mood Points to purchase avatars",
"price":"10",
"product_url":"abc"
};
// calling the API ...
var obj = {
method: 'pay',
order_info: order_info,
purchase_type: 'item'
};
FB.ui(obj, callback);
}
var callback = function(data) {
if (data['order_id']) {
writeback("Transaction Completed! </br></br>"
+ "Data returned from Facebook: </br>"
+ "<b>Order ID: </b>" + data['order_id'] + "</br>"
+ "<b>Status: </b>" + data['status']);
} else if (data['error_code']) {
writeback("Transaction Failed! </br></br>"
+ "Error message returned from Facebook:</br>"
+ data['error_message']);
} else {
writeback("Transaction failed!");
}
};
</script>
function writeback(str) {
$('.get_points').html(str);
}
</script>
And here is button to click:
<input type="button" onclick="placeOrder();" value="GET More POINTS NOW" />
So when I click the button , it says in a facebook popup: Your application is not responding correctly.
So is there some thing missing in code or some thing that need to specify from application settings. Do any one have any idea. Any little thing you can tell is appreciated.
thanks in advance
When you place an order Facebook is making an backend call to your server (to the path set in the application setting page (under credit section).
That error means your application is not replying correctly to that initial call (there are actually two that will take place)
See http://developers.facebook.com/docs/creditsapi/
for more including sample code for your backend.
i am making a facebook application, everything seems done.
here is the sample flow(index.php):
seekpermission.php
processinfo.php
generateresult.php
poststatus.php(the javascript way as told in the documentation)
invitefriends.php(the javascript way as told in the documentation)
hope the names are self explanatory.
the trouble is the dialogue to update status and invite friends comes almost parallely, but what i want is once the user publishes/skips the status message only then should the dialogue of invite friends should come. here is what i tried but it is not working, please help thanks!
FB.ui(
{
method: 'feed',
name: 'name goes here',
link: 'http://apps.facebook.com/****/',
picture: '<?php echo $imageurl; ?>',
caption: 'here is caption',
description: 'the description',
message: '<?php echo $charecter; ?>'
},
function(response) {
if (response && response.post_id) {
alert('<?php include "invitefriends.php"; ?>');
} else {
alert('<?php include "invitefriends.php"; ?>');
}
here is the invitefriends.php
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId:'2****', cookie:true,
status:true, xfbml:true
});
FB.ui({ method: 'apprequests',
message: 'Folks check out my new facebook app!! visit http://apps.facebook.com/**** '});
</script>
</body>
Well, that's a weird way to accomplish a simple task:
You can combine step 4 & 5 in one step:
FB.ui(
{
method: 'feed',
name: 'name goes here',
link: 'http://apps.facebook.com/****/',
picture: '<?php echo $imageurl; ?>',
caption: 'here is caption',
description: 'the description',
message: '<?php echo $charecter; ?>'
},
function(response) {
FB.ui({ method: 'apprequests',
message: 'Folks check out my new facebook app!! visit http://apps.facebook.com/**** '});
/* if (response && response.post_id) {
alert('<?php include "invitefriends.php"; ?>');
} else {
alert('<?php include "invitefriends.php"; ?>');
} */
}
)
As you can see no need for the if else since you will force the invite anyway!
Now if you really need to use your approach, then you may use something like (in the response:
location.href='<?php echo 'path/to/invitefriends.php';
IMPORTANT NOTE:
Most likely ALL your 5 steps can be combined in ONE file, this is better because:
You don't need to load and initialize the JS-library FIVE times!
Will be a better user experience instead of loading each time
You can wrap all the Facebook Calls in JS functions and just call each one in the response of the previous one!
I'm trying to catch event when comment is sent. What am I doing wrong? I just want to update every user comment also to facebook group wall and that's why I need to catch the event.
<fb:comments numposts="10" ></fb:comments>
FB.init and event catcher:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'sensored-app-id',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
/* All the events registered */
FB.Event.subscribe('comments.add', function (response) {
// do something with response
alert("comment added");
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/fi_FI/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
You need to add notify="true" attribute to the fb:comments tag. Once you add the attribute the comments.add event begin to work.
<fb:comments numposts="10" notify="true"></fb:comments>
or, if you're using the newer html5 compliant tags:
<div class="fb-comments" data-num-posts="10" data-notify="true" ></div>
FB.Event.subscribe('comment.create', function(response) {
console.log(response);
});
FB.Event.subscribe('comment.create', function(response) {
FB.api({
method: 'fql.query',
query: "SELECT post_fbid, fromid, object_id, text, time from comment WHERE object_id in (select comments_fbid from link_stat where url ='${session.url}') order by time desc limit 1"
},
function(response) {
var feed = response[0];
alert(feed.text)
}
);
});
You need to be sure to add the notify="true" tag, and if that doesn't work for you, be sure you are using the latest fbComments plugin. Try adding the migrated="1" tag as below, and see if this helps:
<fb:comments notify="true" migrated="1"></fb:comments>
you should note that you have to subscribe for the events after calling FB.init. Works for me now. However, XML Render is having a bug recently
Strangely, if I only have a variable assignment and an ajax post in my comment.create function(response) the event doesn't fire, but if I add a JS alert statement at the bottom or a dud return statement it works?? For example:
FB.Event.subscribe("comment.create", function(response) {
var postData = "page_title='.$safe_page_title.'";
$.ajax({
type: "POST",
url: "/post/post_facebook_comment.php",
data: postData
});
return true;
});