Invite facebook friends in my website using facebook API - asp.net

I am developing a website in C#, using the Facebook API and getting logged in user's friend list. I bind this list in a Datalist with checkbox, friends picture, Name and UserID.
When I check some checkboxes and click on a button, I want to send some sort of invite to the checked friends. I want to send the invite via a private message, notification or any other solution (but not on the user's wall). Is this possible?
I have checked all posts ,which are already in Stackoverflow.
And also checked this one http://www.fbrell.com/xfbml/fb:server-fbml-multi-friend-selector

What you are looking for is called "App-generated Requests". These are requests that are sent from inside your application without needing your users to see or act on the requests dialog.
The following code is taken from the Facebook documentation -
https://developers.facebook.com/docs/channels/#requests
<?php
$app_id = YOUR_APP_ID;
$app_secret = YOUR_APP_SECRET;
$token_url = "https://graph.facebook.com/oauth/access_token?" .
"client_id=" . $app_id .
"&client_secret=" . $app_secret .
"&grant_type=client_credentials";
$app_access_token = file_get_contents($token_url);
$user_id = THE_CURRENT_USER_ID;
$apprequest_url ="https://graph.facebook.com/" .
$user_id .
"/apprequests?message='INSERT_UT8_STRING_MSG'" .
"&data='INSERT_STRING_DATA'&" .
$app_access_token . "&method=post";
$result = file_get_contents($apprequest_url);
echo("App Request sent?", $result);
?>
Once sent, new requests a user has received are visible as a counter
on your application's bookmark and it also increments the counter next
to the appropriate Dashboard.
The code is in PHP but it is using the very generic file_get_contents() method. You can use this logic with any language capable of making HTTP requests.

This code will post on your friend's wall ,whatever you want to post:
for (Int32 i = 1; i < DLFbFriend.Items.Count; i++){
CheckBox Chkbox =(CheckBox)DLFbFriend.Items[i].FindControl("chkUserID");
if (Chkbox.Checked)
{
HiddenField hdfUserId = (HiddenField)DLFbFriend.Items[i].FindControl("hdfUserID");
string d = hdfUserId.Value;//friend's facebook generated id,whom you want to invite
String link = "what ever you want to post";
string url1 = "https://graph.facebook.com/" + d + "/feed?access_token=" + Request.QueryString["access_token"] + "&link=" + link + "&from=" + Session["Pinny_USER"].ToString().Split('~')[0] + "&name=Register with Pinny&message=Your friend invites you&picture=http://168.144.124.15/images/logoPinny.jpeg";
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1);
request1.Method = "POST";
// execute the request
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
// we will read data via the response stream
System.IO.Stream ReceiveStream1 = response1.GetResponseStream();
StreamReader readStream1 = new StreamReader(ReceiveStream1);
string json1 = readStream1.ReadToEnd();
countinvited += 1;
}
}

Related

ASP.NET Cant Open link via email

I created an email in ASP.NET and I want to add a link to the body, but this not a normal url, its a file that is created via byte array and now I want that file to be linkable in my email, but no matter what I do the link is clickable but nothing opens, here is my code:
FileContentResult eventPass = new FileContentResult(generatedPass, "application/vnd.apple.pkpass");
eventPass.FileDownloadName = "preview.pkpass";
message += "<a href='//" + eventPass + "' target='_blank'>Click Here</a>";
AlternateView alternateView = AlternateView.CreateAlternateViewFromString(message, null, MediaTypeNames.Text.Html);
alternateView.LinkedResources.Add(inline);
email.AlternateViews.Add(alternateView);
email.IsBodyHtml = true;
email.Headers.Add("Content-Type", "application/vnd.apple.pkpass");
I know the file is generated correctly because if I return eventPass the file downloads.
Do I need to save eventPass to the server?
Possible answer here:
How to set mime type of application/vnd.apple.pkpass in order to share pass by link or email
Please mark my answer as correct if this has helped you.

PHPMailer sending twice

Inherited some PHPMailer code in a WordPress theme and cannot figure out why the following is sending 2 duplicate emails with the same timestamps in the body.
$mail = new PHPMailer;
$mail->From = $_POST['form_email'];
$mail->FromName = $_POST['form_name'];
$mail->addAddress('craig#myemail.com'); // Send email to
$mail->isHTML(true);
$mail->Subject = 'Entry';
$mail->Body = '
<p>Submitted: '.date('d/m/Y H:i:s').'</p>
';
if ( !$mail->send() ) {
$response->result = false;
}
Timestamps only have a 1-second resolution, so it's very likely that this is a double request by your browser - it's a common problem with some extensions. It's easy to test - stick a random number on the end of your subject:
$mail->Subject = 'Entry '.rand();
If the numbers in your messages are different, you'll know your script is being run twice.
It also won't help that you're forging the from address, that's a good way to cause delivery problems - read the PHPMailer docs.

Restricting email notification for private site in alfresco

I have added a script to send mail whenever a site is created. How to restrict the email notification if the site created is a private site. Here is my java script
var mail = actions.create("mail");
var node = people.getGroup("GROUP_EMAIL_CONTRIBUTORS");
if(node){
var members = people.getMembers(node);
}
mail.parameters.from = "Administrator#community.com"
mail.parameters.subject=" A new site called " + document.properties.name+" is created";
mail.parameters.text="Click http://sameer_w7:8080/share/page/site/" + document.properties.name + "/dashboard" + " to join the site";
for(var i=0;i<members.length;i++)
{
mail.parameters.to = members[i].properties.email;
//execute action against a document
mail.execute(document);
}
You can get the siteVisibility state of a site.
Take a look at the SiteService Wiki page.
Something like this should work:
if (document.properties["st:siteVisibility"] != "PRIVATE"){
<your email action here>
}
Be sure you have selected type is st:site in your rule, otherwise add an extra check on that.

Google Gmail API - Auth

I already have code which works fine, but for security reason I want to make other way of Auth.
In this case, user writes his username and password, but I want to make like "Allow demo.com to access your information's" click button.
How to change this code:
//Provide Login Information
Google.GData.Client.RequestSettings rsLoginInfo = new Google.GData.Client
.RequestSettings("", txtEmail.Text, txtPassword.Text);
rsLoginInfo.AutoPaging = true;
// Fetch contacts and dislay them in ListBox
Google.Contacts.ContactsRequest cRequest = new ContactsRequest(rsLoginInfo);
Google.GData.Client.Feed<Google.Contacts.Contact> feedContacts = cRequest
.GetContacts();
foreach (Google.Contacts.Contact gmailAddresses in feedContacts.Entries) {
Console.WriteLine("\t" + gmailAddresses.Title);
lstContacts.Items.Add(gmailAddresses.Title);
foreach (EMail emailId in gmailAddresses.Emails) {
Console.WriteLine("\t" + emailId.Address);
lstContacts.Items.Add(" " + emailId.Address);
}
}
It seems like you're trying to do 3-Legged OAuth. .NET samples for performing 3-Legged OAuth 1.0a are documented here:
http://code.google.com/apis/gdata/docs/auth/oauth.html#Examples

flex application bind to url

The problem with flex applications is that a user can download it and run it on his local machine or possibly host it on another site. Is it possible to lock a flex application to a domain name to prevent such acts?
Sure, you'll do something like this in your application initialization area :
var domainList : String = 'mysite.com,anothersite.com';
var domainCheck : String = this.url.split('/')[2];
var foundValidDomain : Boolean = false;
for each ( var domainChecking : String in domainList.split(',')){
if( domainCheck.toUpperCase().indexOf(domainChecking.toUpperCase()) >= 0 ){
mx.controls.Alert.show( 'check success: "' + domainCheck + '" against: "' + domainChecking );
foundValidDomain = true;
break;
}else{
mx.controls.Alert.show( 'check failed: "' + domainCheck + '" against: "' + domainChecking );
}
}
if( !foundValidDomain ){
// oh noes! mad hax!
this.visible = false; // or however you want to lock it down
return;
}
Make sense? :)
Now, if you want to lock it down more, you can have your app post to a server with a key string and have the server send some encrypted time-sensitive instructions back (send date/time to server and back, etc). This would add another layer of hassle having to implement the server side as well. This is probably overkill for most applications.
You'll have to write the code yourself, but you could access the URL variable of the application tag and disable the app if the domain is not your domain.
I wouldn't call this an unbeatable measure, but I don't think anything is.
I'm not sure why this 'problem' is unique to Flex applications.
Take a look at this link http://www.richardlord.net/blog/protecting-a-swf
Basically, you can solve the problem by locking down the domain as you say, and also you can potentially encrypt your code using commercial solutions - which are discussed in the link. I think the main point is if you publish Flex code externally you want people to run it.

Resources