Sharing url to Facebook from AS3 website - facebook

I'm trying to share a URL from a flash as3 website, and i can't make it work quite properly...
I tried both ways given here : How to create a share button in AS3
First one works :
import flash.net.navigateToURL;
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
share_btn.addEventListener(MouseEvent.CLICK, shareClickHandler);
function shareClickHandler(evt:MouseEvent):void
{
var varsShare:URLVariables = new URLVariables();
varsShare.u = 'http://domain.com/pageN.html';
varsShare.t = 'Title Page';
var urlFacebookShare:URLRequest = new URLRequest('http://www.facebook.com/sharer.php');
urlFacebookShare.data = varsShare;
urlFacebookShare.method = URLRequestMethod.GET;
navigateToURL(urlFacebookShare, '_blank');
}
But, the post says :
In order to use a picture add the following Metatags:
<meta name="title" content="my title" />
<meta name="description" content="my description" />
<link rel="image_src" href="images/thumbnail_image.jpg" />
But HOW ????
The second solution shows how to add parameters:
var req:URLRequest = new URLRequest();
req.url = "http://www.facebook.com/dialog/feed";
var vars:URLVariables = new URLVariables();
vars.app_id = "000000000000"; // your application's id
vars.link = "http://YourSite.com";
vars.picture = "https://www.google.com/intl/en_com/images/srpr/logo3w.png";
vars.name = "name name";
vars.caption = "caption caption caption";
vars.description = "description description description";
vars.message = "message message message message message";
vars.redirect_uri = "http://YourSite.com";
req.data = vars;
req.method = URLRequestMethod.GET;
navigateToURL(req, "_blank");
But it's NOT using the Facebook sharer.....
I tried many many different ways to combine both solutions but i get nothing but weird url not working...
Please, can someone help me with that, or show me how to use that second solution but with the sharer ?
Thanks a lot for any help

You need to add OpenGraph Meta Tags to the Page you are trying to share (http://domain.com/pageN.html in your example above`). The metatags you've given in your question should be added there so the Facebook Sharing Script can pick it up.
Add the below code between the <head> and </head> tags in your HTML code:
<meta name="title" content="my title" />
<meta name="description" content="my description" />
<link rel="image_src" href="images/thumbnail_image.jpg" />

what I usually do - I create a facebook application - Website with Facebook Login, add Apps domains, then in your html add this javascript function:
function postToFacebook(link){
var caption = encodeURIComponent("this is cool");
var name = encodeURIComponent("My cool Site");
var pathToPicture = "http://yoursite.com/coolpicture.jpg";
var redirect = "http://yoursite.com/redirect.html";
var id = "123456789098876"; // your application id
var theLink = link; // the link you want to share - this is passed as a variable from flash, similary you can pass any variables from flash
var fbencoded = "http://www.facebook.com/dialog/feed?app_id=" + id + "&link=" + theLink + "&picture=" + pathToPicture + "&name=" + name + "&caption=" + caption+ "&redirect_uri=" + redirect;
window.open(fbencoded, "_blank");
}
In flash whenever you want to share just call this javascript function and new window will be opened with facebook share window:
ExternalInterface.call("postToFacebook", "http://mysite.com/#/cool-page")
This way you can pass any vars to that function. For example you can have different pictures whenever someone is sharing, which would be impossible with just meta tags.....
Only thing is you have to create that redirect.html - which must be within your domain, that is linked to your application. In redirect you can have something simple as this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="REFRESH" content="0;url=http://www.facebook.com">
</head>
<body>
</body>
</html>
It would just redirect the user to facebook.
Hope this helps.

This is the way I got to use the Share Dialog from a button in AS3. I hope it helps you
import flash.net.navigateToURL;
share_btn.addEventListener(MouseEvent.CLICK, shareClickHandler);
function shareClickHandler(evt:MouseEvent):void
{
var fb_title = "titulo";
var fb_desc = "descripcion";
var fb_url = "http://mibff.com.mx/";
var fab_img = "http://mibff.com.mx/MiBFF_new.jpg";
var facebookSharer:String = "http://www.facebook.com/sharer.php?s=100&p[title]=" + fb_title + "&p[summary]=" + fb_desc + "&p[url]=" + fb_url + "&p[images][0]=" + fab_img;
var jscommand:String = "window.open('" + facebookSharer + "','win','width=626,height=316,toolbar=no,scrollbars=no,resizable=no');";
var sharer:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
navigateToURL(sharer,"_self");
//trace(facebookSharer);
}

Related

PayPal Subscriptions

I am trying to get a PayPal access token using the instructions at this URL: https://developer.paypal.com/docs/api/overview/#get-an-access-token
I have followed the instructions at the URL to the letter and have built the following sample code in JavaScript. When I run it I get a 401 error - user not authorized.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>Get Access Token</h1>
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.log(xhttp.responseText);
}
else {
console.log("Status: " + xhttp.status)
}
};
url = "https://api.sandbox.paypal.com/v1/oauth2/token"
clientID = "AY_6HpYodeIdCyCSWmIuTTX6P4PfcO1tcehekaSk9uwSBhav1SILCD0MZ_E3dRMVXiPdmE-YimahYtQy"
secret = "EHLlKnunCQtuTdqjnl6QX9ZnuQgMllZKozf-VNHeys9tDssQc0xlXi4_0se1M-VxT8gOHGaSVS3M-2an"
xhttp.open("post", url, false, clientID, secret);
xhttp.setRequestHeader("Accept", "application/json");
xhttp.setRequestHeader("Accept-Language", "en_US");
xhttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xhttp.send("grant_type=client_credentials");
console.log(xhttp.status);
</script>
</body>
</html>
The clientID and secret came from the PayPal My Apps and Credentials link:
PayPal My Apps and Credentials Page
Can anyone help? Thanks
I found the answer. The following code works. The client id and secret should not be passed as parameters to the Open command, the way I had it.
Instead, they must be concatenated with each other, with a colon in between, then (believe it or not) base 64 encoded and passed in the Authorization header, as shown:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>Get Access Token</h1>
<script>
clientID = "AY_6HpYodeIdCyCSWmIuTTX6P4PfcO1tcehekaSk9uwSBhav1SILCD0MZ_E3dRMVXiPdmE-YimahYtQy"
secret = "EHLlKnunCQtuTdqjnl6QX9ZnuQgMllZKozf-VNHeys9tDssQc0xlXi4_0se1M-VxT8gOHGaSVS3M-2an"
var authorizationString = btoa(clientID + ':' + secret);
/////////////////////////////////////////////////////////////////////////////////////////////
var xhttp = new XMLHttpRequest();
var createPlanResults = ""
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
document.write(xhttp.responseText)
}
};
url = "https://api.sandbox.paypal.com/v1/oauth2/token"
xhttp.open("post", url, false);
xhttp.setRequestHeader("Accept", "application/json");
xhttp.setRequestHeader("Accept-Language", "en_US");
xhttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xhttp.setRequestHeader("Authorization", "Basic " + authorizationString);
xhttp.send("grant_type=client_credentials");
</script>
</body>
</html>

wpcf7 dynamic email-tag content

Description:
WordPress Contact Form 7;
Mailing using smtp;
Form Settings: "use html-format" + "mail2 use html-format" checked;
Form Settings: Email body : just one mail-tag [calculated-template];
Problem with paragraph tag solved (all mail-tags upon receiving are shown inside "p" html-tag);
[calculated-template] is a mail-tag dynamically filled with html, based on submitted objects handled by VueJS2 on frontend;
[calculated-template] is populated by hooking at action 'wpcf7_posted_data':
add_action('wpcf7_posted_data', array('vue_handler','handle'), 1, 1);
vue_handler::handle($data) receives $data array with some wpcf7 data which can be modified. Contents of $data array:
_wpcf7 = "1166"
_wpcf7_version = "4.9.2"
_wpcf7_locale = "ru_RU"
_wpcf7_unit_tag = "wpcf7-f1166-p1167-o1"
_wpcf7_container_post = "1167"
columns-stringified = ""
fences-stringified = ""
your-name = "name"
your-email = "email#test.com"
calculated-template = ""
Then vue_handler::handle($data) injects html into email-tag [calculated-template].
Problem:
Finally [calculated-template] html-contents rendered escaped (Mailtrap.io, "HTML Source" tab):
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
</head>
<body>
<h1>Example Header</h1>
</body>
</html>
The main idea of the snippet: opening and closing html-tag symbols "<", ">" rendered escaped: "<", ">";
SOLVED
By using another hook wpcf7_before_send_mail
In which I fully replaced mail body with my dynamic html.
List of all hooks:
http://hookr.io/plugins/contact-form-7/4.5.1/hooks/#index=a

Adding inline images to Mailgun emails using Scala and Play WS

I can succesfully make POST requests to Mailgun and receive the emails as expected. I'm trying to inline an image into an email and can't work out how to do it.
Looking at https://documentation.mailgun.com/user_manual.html#sending-via-api and selecting Java, I can see that the example given constructs a FileDataBodyPart with "inline", the File reference and the MediaType. Looking at the curl example, this seems rather unnecessary as that just references a file.
Here is my method for sending an email:
def send(message:EmailMessage) = {
val postMessage = Map("from" -> Seq(message.from), "to" -> Seq(message.to), "subject" -> Seq(message.subject), "text" -> Seq(message.text), "html" -> Seq(message.html.toString()))
val logo = FileBody(Play.getExistingFile("/public/images/logo.png").get)
WS.url(apiUrl).withAuth("api", myKey, WSAuthScheme.BASIC).withBody(logo).post(postMessage)
}
The message.html.toString looks like the following:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body style="background-color:#9B59B6; padding:10px">
<img src="cid:logo.png">
<h1 style="color:#FFF">Activate!</h1>
</body>
</html>
The logo.png file is found when sending the email and the email comes through fine, but with no image. This is what the email source looks like once it arrives at gmail:
Mime-Version: 1.0
Content-Type: text/html; charset="ascii"
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body style="background-color:#9B59B6; padding:10px">
<img src="cid:logo.png">
<h1 style="color:#FFF">Activate!</h1>
</body>
</html>
I can't see any base64 encoding of the image in the email. As the curl example appeared to just be passing a file as part of the POST, I though I'd try that. Here is what I did:
def send(message:EmailMessage) = {
val logoFile = Play.getExistingFile("/public/images/logo.png").get
val source = Files.readAllBytes(Paths.get(logoFile.getAbsolutePath))
val logoBase64 = Base64.encodeBase64String(source)
val postMessage = Map("from" -> Seq(message.from), "to" -> Seq(message.to), "subject" -> Seq(message.subject), "text" -> Seq(message.text), "html" -> Seq(message.html.toString()), "inline" -> Seq(logoBase64))
WS.url("https://api.mailgun.net/v2/sandboxaa9afcea1f2e4d5db5e2c080f7784b74.mailgun.org/messages").withAuth("api", "key-f165695d4c72e929ff8215115e648c95", WSAuthScheme.BASIC).post(postMessage)
}
I converted the logo into base64 and POSTed that like the other parameters. Still no joy.
What am I missing here? Do I need to pass this in the body, but somehow specify that this is an "inline" file?
I solved this by using Jersey, as suggested in the section on libraries: https://documentation.mailgun.com/libraries.html#java
I imported Jersey in sbt using the following:
libraryDependencies += "com.sun.jersey" % "jersey-core" % "1.18.3"
libraryDependencies += "com.sun.jersey" % "jersey-client" % "1.18.3"
libraryDependencies += "com.sun.jersey.contribs" % "jersey-multipart" % "1.18.3"
and then created my Email sending object like so:
object Email {
val client = Client.create()
client.addFilter(new HTTPBasicAuthFilter("api", current.configuration.getString("mailgun.api.key").get))
val webResource = client.resource(current.configuration.getString("mailgun.api.url").get)
def send(message:EmailMessage) = {
val form = new FormDataMultiPart
form.field("from", message.from)
form.field("to", message.to)
form.field("subject", message.subject)
form.field("text", message.text)
form.field("html", message.html.toString())
val logo = Play.getExistingFile("/public/images/logo.png").get
form.bodyPart(new FileDataBodyPart("inline", logo, MediaType.APPLICATION_OCTET_STREAM_TYPE))
webResource.`type`(MediaType.MULTIPART_FORM_DATA_TYPE).post(form)
}
}
I hope this helps someone.

phonegap submit form, how to send to my email

I am building simple phonegap android app.
i make simple html form with few input fields (Name, Last name, Question).
I want that when user fill input fields (Name, Last name, Question) and click Submit to send to my email address. Just that.
Do you have any idea how to do that with phonegap?
Thank you
You could do it easily by using php or .net (as your selection) with AJAX Call
Just Create One HTML page which display form to User for filling up data and send it.
Here I saw you how I done with PHP (Use phpmailer. for more, visit : http://phpmailer.worxware.com/index.php?pg=examplebmail)
HTML Form
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<form action="#!" method="post">
<input type = "text" name="cname" />
<input type = "number" name="cnumber" />
<input type = "email" name="cemail" />
<input type = "submit" value="Submit" onclick="UpdateRecord()" />
</form>
<script>
function UpdateRecord()
{
// Social Links
GolbalURL = "http://www.yourserverpathtophpfile.com";
var cname = $("[name='cname']").val();
var cnumber = $("[name='cnumber']").val();
var cemail = $("[name='cemail']").val();
jQuery.ajax({
type: "POST",
url: GolbalURL+"sendemail.php",
data: "cname="+ cname+"& cnumber="+ cnumber+"& cemail="+ cemail,
dataType: "html",
cache: false,
success: function(response)
{
alert("Email Sent");
}
});
}
</script>
</body>
</html>
Sendmail.php
<?php
$cname = $_REQUEST['cname'];
$cnumber = $_REQUEST['cnumber'];
$cemail = $_REQUEST['cemail'];
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = "Name : ".$cname."Number : ".$cnumber."Email : ".$cemail;
$mail->SetFrom($cemail, $cname);
$address = "youremail#id.com";
$mail->AddAddress($address, "Your Name");
$mail->Subject = "Your Subject";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Do not forgot to upload your dynamic files to server and give it permissions. Or You can also call device's default mail application from code, check PHONEGAP EMAIL COMPOSER
GIT Link Of Email Compo.
https://github.com/katzer/cordova-plugin-email-composer/blob/172605ee12e58d5e5809e4e031b3b96cead143ac/README.md
You can do using Cordova EmailComposer Plugin for Android . Add this function on your submit button click. For installation follow these steps .
https://github.com/katzer/cordova-plugin-email-composer
function emailComposer(){
window.plugin.email.isServiceAvailable(
function (isAvailable) {
if(isAvailable){
window.plugin.email.open({
to: [''],
cc: [''],
bcc: [''],
subject: '',
body: ''
});
}else{
alert('Service is not available');
}
}
);
}
**JQUERY - CALL PHP SCRIPT TO POST DATA**
var ajax_call = serviceURL;
var form_data = $('#form').serialize();
$.ajax({
type: "POST",
url: ajax_call,
data: form_data,
dataType: "json",
success: function(response) {
//called when successful
},
error: function(e) {
//called when there is an error
//console.log(e.message);
}
});
Examples
There are plugins to compose emails, but it won't send it automatically. You really need to use a back end service to handle this for you. You can setup your own using any app language (PHP, ColdFusion, etc), or consider a service like WuFoo perhaps.

cross rider extension to fetch new posts from feed using google feeds api

I am trying to create an extension to display all the latest posts fetched from my feed using google feeds api. To implement this, I have added this code in background.js:
appAPI.ready(function() {
// Global variable to hold the toggle state of the button
var buttonState = true;
// Sets the initial browser icon
appAPI.browserAction.setResourceIcon('images/icon.png');
// Sets the tooltip for the button
appAPI.browserAction.setTitle('My Postreader Extension');
appAPI.browserAction.setPopup({
resourcePath:'html/popup.html',
height: 300,
width: 300
});});
and in popup.html,
<!DOCTYPE html><html><head><meta http-equiv="X-UA-Compatible" content="IE=edge">
<script type="text/javascript">
function crossriderMain($) {eval(appAPI.resources.get('script.js')); }</script>
</head>
<body><div id="feed"></div></body></html>
The script.js file is-
google.load("feeds", "1");
function initialize() {
var feed = new google.feeds.Feed("http://www.xxxxx.com/feed/");
feed.setNumEntries(10);
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById("feed");
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var div = document.createElement("div");
var link = document.createElement('a');
link.setAttribute('href', entry.link);
link.setAttribute('name', 'myanchor');
div.appendChild(document.createTextNode(entry.title));
div.appendChild(document.createElement('br'));
div.appendChild(link);
div.appendChild(document.createElement('br'));
container.appendChild(div);
}
}
});
}
google.setOnLoadCallback(initialize);
But I am unable to get desired result.The popup doesn't display anything.It just remain blank.
Since you are using a resource file for the popup's content, it's best to load the remote script from the crossriderMain function, as follows:
<!DOCTYPE html>
<html>
<head>
<!-- This meta tag is relevant only for IE -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script type="text/javascript">
function crossriderMain($) {
appAPI.db.async.get('style-css', function(rules) {
$('<style type="text/css">').text(rules).appendTo('head');
});
appAPI.request.get({
url: 'http://www.google.com/jsapi',
onSuccess: function(code) {
$.globalEval(code);
appAPI.db.async.get('script-js', function(code) {
// runs in the context of the extension
$.globalEval(code.replace('CONTEXT','EXTN'));
// Alternatively, run in context of page DOM
$('<script type="text/javascript">').html(code.replace('CONTEXT','PAGE DOM')).appendTo('head');
});
}
});
}
</script>
</head>
<body>
<h1>Hello World</h1>
<div id="feed"></div>
</body>
</html>
[Disclaimer: I am a Crossrider employee]