Post from Flash to PHP in Facebook app - php

I published 2 days ago a Facebook app, it's a flash game, after the game over, the flash file POST score to my php file, Publish your score to wall if you beat your highscore, Facebook disabled the application because bad reviews from users.
How to POST from Falsh to PHP without redirecting the user, i want after the game over POST score, insert it in DB, and show the user Stream Publish popup if he want to publish to wall the score or not.
The flash game is developped by Adobe Flash CS3, AS2.
Any idea please,

To send data back to your server, you can write:
var sender = new LoadVars();
sender.x = "xxx";
sender.y = "yyy";
sender.z = "zzz";
sender.send("http://www.yourdomain.com/yourscript.php", "", "post")
To sendAndLoad
In case you want to get back data at the same time you send your data back to the server, you can use the sendAndLoad api:
var loader = new LoadVars();
loader.onLoad = function(success) {
if(success) {
// read your data here, e.g.
trace(this.x); // suppose the server send back a variable x
trace(this.y); // and a variable y
}
}
var sender = new LoadVars();
sender.x = "xxx";
sender.sendAndLoad("http://www.yourdomain.com/yourscript.php", loader, "post");

This is quite simple. Some example code here:
http://codesnippets.joyent.com/posts/show/566

Related

PHP how to handle get started button Messenger postback with a chat bot

I am working on a Messenger chatbot in development mode and have made some progress dealing with messages and quick replies but can't find the way to detect the Postback payload event sent by Facebook after the user press the "Get Started Button"
I have set the Get Started button postback and put the payload string by sending a POST request to the Messenger Profile API which returned "success", and had also set the "messaging_postbacks" event to my webhook.
However when the button is clicked the event is not detected by the webhook.
This is part of my code:
$input = json_decode(file_get_contents('php://input'), true);
$sender = $input['entry'][0]['messaging'][0]['sender']['id'];
//this handles the message text properly
$message = $input['entry'][0]['messaging'][0]['message']['text'];
//this deals correctly with quick reply payload
$quickreply = $input['entry'][0]['messaging'][0]['message']['quick_reply']['payload'];
I have tried separately and unsuccessfully each one of this lines of code to get the postback input triggered by the get started button:
$getstarted = $input['entry'][0]['messaging'][0]['get_started']['payload'];
$getstarted = $input['entry'][0]['messaging'][0]['message']['get_started']['payload'];
$getstarted = $input['entry'][0]['messaging'][0]['postback']['payload'];
$getstarted = $input['entry'][0]['messaging'][0]['message']['postback']['payload'];
I will appreciate any suggestions :)
The way to retrieve the value of the get_started button was among the ones I had tried, specifically:
$input['entry'][0]['messaging'][0]['postback']['payload']
The issue had to do with a separate part of my code in the cURL thats sends the POST request.
It said:
if(!empty($input['entry'][0]['messaging'][0]['message'])){
$result = curl_exec($ch);
And needed to say:
if(!empty($input['entry'][0]['messaging'][0]['postback'])){
$result = curl_exec($ch);
The get_started button sends a postback to the webhook so the first script wasn't initiating the cUrl because there was no 'message' in the $input variable but a 'postback' property
A good video resource that dealt the same issue: https://www.youtube.com/watch?v=JQkmznEfVDo

Piwik tracking API returns GIF89

I guess I'm missing something basic here, but when I try out the example from here (adapted to my context):
<?php
$piwikTracker = new PiwikTracker( $idSite = {$IDSITE} );
// Specify an API token with at least Admin permission, so the Visitor IP address can be recorded
// Learn more about token_auth: https://piwik.org/faq/general/faq_114/
$piwikTracker->setTokenAuth('my_token_auth_value_here');
// You can manually set the visitor details (resolution, time, plugins, etc.)
// See all other ->set* functions available in the PiwikTracker.php file
$piwikTracker->setResolution(1600, 1400);
// Sends Tracker request via http
$piwikTracker->doTrackPageView('Document title of current page view');
// You can also track Goal conversions
$result = $piwikTracker->doTrackGoal($idGoal = 1, $revenue = 42);
?>
the $result variable contains
GIF89a�����������!�����,�������D�;
which I'm told is a small tracking GIF. But why on earth would the API return a tracking GIF? Shouldn't it rather be a status result about success/failure?

Access shared mailbox through o365 v2 api

So I got access to the new o365 v2 api and it's working pretty good so far. I am however having trouble accessing any shared inboxes.
Even worse, there doesn't appear to be any error message being returned:
#odata.context = https://outlook.office.com/api/v2.0/$metadata#Me/Messages(Subject,ReceivedDateTime,SentDateTime,Sender,From,ToRecipients,CcRecipients,BccRecipients,ReplyTo,ConversationId,IsRead,InternetMessageId
[value] =
Has anyone ever tried this?
To clarify, this isn't for exchange, but outlook.com
It seems that you were using the delegate-token to request the message from the specific user for the messages in a shared box.
The Office 365 REST API only support app-level token to get the messages from the organization. The delegate-token only could get the messages of the delegatee user.
You can also consider using the EWS to retrieve the messages of shared box as a workaround.
Here is an example for your reference:
string userName = "";
string password = "";
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new NetworkCredential(userName, password);
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl(userName, RedirectionUrlValidationCallback);
FolderId SharedMailbox = new FolderId(WellKnownFolderName.Inbox, "sharedmailbox#consoto.onmicrosoft.com");
ItemView itemView = new ItemView(10);
var results = service.FindItems(SharedMailbox, itemView);
foreach (var item in results)
{
Console.WriteLine(item.Subject);
}
And if you want the Office 365 REST API to support this feature, you can also submit the feedback from here.

C2DM: What to do with registration id in the 3rd party php server?

I have setup the Android part for C2DM, and here's a part of the code:
private void handleRegistration(Context context, Intent intent) {
// (...)
else if (registration != null) {
Log.d("c2dm", registration);
Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
editor.putString(REGISTRATION_KEY, registration);
editor.commit();
// Send the registration ID to the 3rd party site that is sending
// the messages.
// This should be done in a separate thread.
// When done, remember that all registration is done.
}
}
So it says to send the registration ID to my server. What should I do with it, and how can I send messages in php?
Code examples would be great, as I'm not very experienced with PHP. I've seen this answer, but that uses sessions, which I'm not using.
You need to save it to a database like MySQL so you will be able to access it later when you want to push to the device.
Then you'll send it somewhat like this
include("class.c2dm.php");
$c = new C2DM();
$c->setUsername('appemail#gmail.com');
$c->setPassword('emailpassword');
$c->setSource('com.company.app.package');
$c->setAuthCode($c->getAuthCode());
$regid = "longdeviceid"; //this is the device you want to push to. pull from your database.
$response = $c->send($regid, 'TRACK', array('action' => 'start_tracking'));
echo $response;
Get class.c2dm.php here:
https://bitbucket.org/Dianoga/php-c2dm/src/0c299de8f10b/class.c2dm.php

Facebook graph api Friend Invitations

I have managed to send and retrieve data from facebook for invitatin using
FB.ui({
method: 'apprequests',
to: sendto,
message: 'Win Mega Prizes!',
title: 'Enter in this contest!'
},
function (response) {
if (response && response.request_ids) {
var requests = response.request_ids.join(',');
alert(requests);
window.location.href = "http://www.rmyserver/index.php?invitations="+requests+"&contest_id="+c_id+"&page_id="+page_id+"&user="+from+"&g_id="+g_id+"&sendto="+sendto+"&single=1";
} else {
alert('canceled');
}
PHP
foreach($requests as $request_id) {
// Get the request details using Graph API
echo $request_content = json_decode(file_get_contents("https://graph.facebook.com/$request_id?$app_token"), TRUE);
But i want to use single user app request , as per docs i need to use TO: filed but this doesnt work, request is sent as well i get invitation id but php code used above returns false.
Am i missing something
you can try direct url example given here https://developers.facebook.com/docs/reference/dialogs/requests/#frictionless_requests
that should work fine from php
This works for me:
FB.ui({
method:'apprequests',
message:'I want you to open up your heart a little.',
to:123456798,
// filters:['app_non_users'], // commented: let users send notifications to app users too, probably a good idea to make them revisit?
data:'' // send data what you would like to track, FB will send that back in the URL for us
// #todo send google campaign parameters
});
Moreover you are doing it wrong on PHP side, you would need to redirect the user to a URL where the invitation friend selector would be displayed. There is no way in my knowledge to directly send an invitation to users using PHP.

Categories