I created a facebook app. A small game in asp.net mvc. It is a real time turn based game and i want the first player to choose his opponent, send him a facebook notification and go to the page of tthe game. The second player then clicks on this notification and also go the the page of the game. My problem is about the href parameter of the post data. In asp.net i create a webhttprequest object. But my data i have to post is like that :
But when second player click on notification the last two parameters are lost. I think it is because symbol & is used with facebook graph address and with my address. How can i write the correct postdata with all the parameters ??
Here is my code :
public string sendnotificationtoplay(string monid, string prenomMoi, string codetokenjeu){
try
{
// variables to store parameter values
string url = "https://graph.facebook.com/" + monid + "/notifications";
string autrePrenom = "#[" + monid + "]";
string texte = "#[" + monid + "] ! " + prenomMoi + " wants to play with you ! \n Click here !";
// creates the post data for the POST request
string postData = ("access_token=MYACCESSTOKEN&template=" + texte + "&href=mywebsite.org/Index?ordredemandejeugame=2&codejeuadeux=ds&prenom1=dfdf&prenom2=fdgdfg");
// create the POST request
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = postData.Length;
// POST the data
using (StreamWriter requestWriter2 = new StreamWriter(webRequest.GetRequestStream()))
{
requestWriter2.Write(postData);
}
// This actually does the request and gets the response back
HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse();
string responseData = string.Empty;
using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
{
// dumps the HTML from the response into a string variable
responseData = responseReader.ReadToEnd();
}
return responseData;`
I am trying to get facebook page feed ( public posts) which does not require any access token.
here's the url
https://www.facebook.com/feeds/page.php?format=json&id=1393547494231876
when i run this in browser where id= any facebook page id. it returns first 25 public posts in json format.
but when i run this in my code to get json result facebook return a page saying "unsupported browser"
this is my method . i pass it facebook page id to get posts..
public static String GetPosts(string PageId)
{
string id = PageId;
string apilink = "https://www.facebook.com/feeds/page.php?format=json&id=";
HttpWebRequest request = WebRequest.Create(apilink + id) as HttpWebRequest;
request.Method = WebRequestMethods.Http.Get;
request.Accept = "application/json";
request.ContentType = "application/json; charset=utf-8";
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Console application output
String result = reader.ReadToEnd();
return result;
}
}
Here's the result that i get in return string
Result Image String
and so on remaining page returned.
Can somebody help me how to get it working??
Update
Found Answer...
I Have To Set User agent to make Facebook think i am a browser..
so just added
request.UserAgent = ".NET Framework";
and i worked.
Thanks to All.
Found Answer... I Have To Set User agent to make Facebook think i am a browser.. so just added request.UserAgent = ".NET Framework"; and i worked. Thanks to All.
I am working in a .NET Web Application(Web Forms).I need to embed the document signing experience into my web application,preferably by means of an Iframe.
Is is possible to authenticate to docusign from the web application and then bring the signing experience in an Iframe?
Also is it possible to re-direct to a custom URL on signing complete,signing declined,window closed..etc?
This is a copy of the API walkthrough on how to do embedded signing in C#. You can find other walkthroughs here: http://iodocs.docusign.com/APIWalkthroughs.
The code below should do exactly what you are looking for - give you an authenticated IFRAME ready for signing. Before using this you should create a template with your document and place the signature tabs in the places where you want someone to sign.
// DocuSign API Walkthrough 08 in C# - Embedded Signing
// To run this sample:
// 1) Create a new .NET project.
// 2) Add 3 assembly references to the project: System, System.Net, and System.XML
// 3) Update the username, password, integrator key, and templateId in the code
// 4) Compile and Run
//
using System;
using System.IO;
using System.Net;
using System.Xml;
using System.Text;
namespace APIWalkthrough08
{
public class EmbeddedSigning
{
// Enter your info:
static string username = "***";
static string password = "***";
static string integratorKey = "***";
static string templateId = "***";
static string roleName = "***";
public static void Main ()
{
string url = "https://demo.docusign.net/restapi/v2/login_information";
string baseURL = ""; // we will retrieve this
string accountId = ""; // will retrieve
string envelopeId = ""; // will retrieve
string uri = ""; // will retrieve
string authenticateStr =
"<DocuSignCredentials>" +
"<Username>" + username + "</Username>" +
"<Password>" + password + "</Password>" +
"<IntegratorKey>" + integratorKey + "</IntegratorKey>" +
"</DocuSignCredentials>";
//
// STEP 1 - Login
//
try {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (url);
request.Headers.Add ("X-DocuSign-Authentication", authenticateStr);
request.Accept = "application/xml";
request.Method = "GET";
HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse ();
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
string responseText = sr.ReadToEnd();
using (XmlReader reader = XmlReader.Create(new StringReader(responseText))) {
while (reader.Read()) { // Parse the xml response body
if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "accountId"))
accountId = reader.ReadString();
if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "baseUrl"))
baseURL = reader.ReadString();
}
}
//--- display results
Console.WriteLine("accountId = " + accountId + "\nbaseUrl = " + baseURL);
//
// STEP 2 - Request Envelope Result
//
// Construct an outgoing XML request body
string requestBody = "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" +
"<accountId>" + accountId + "</accountId>" +
"<status>sent</status>" +
"<emailSubject>API Call for Embedded Sending</emailSubject>" +
"<emailBlurb>This comes from C#</emailBlurb>" +
"<templateId>" + templateId + "</templateId>" +
"<templateRoles>" +
"<templateRole>" +
"<email>" + username + "</email>" + // NOTE: Use different email address if username provided in non-email format!
"<name>Name</name>" + // username can be in email format or an actual ID string
"<roleName>" + roleName + "</roleName>" +
"<clientUserId>1</clientUserId>" +
"</templateRole>" +
"</templateRoles>" +
"</envelopeDefinition>";
// append "/envelopes" to baseUrl and use in the request
request = (HttpWebRequest)WebRequest.Create (baseURL + "/envelopes");
request.Headers.Add ("X-DocuSign-Authentication", authenticateStr);
request.ContentType = "application/xml";
request.Accept = "application/xml";
request.ContentLength = requestBody.Length;
request.Method = "POST";
// write the body of the request
byte[] body = System.Text.Encoding.UTF8.GetBytes (requestBody);
Stream dataStream = request.GetRequestStream ();
dataStream.Write (body, 0, requestBody.Length);
dataStream.Close ();
// read the response
webResponse = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(webResponse.GetResponseStream());
responseText = sr.ReadToEnd();
using (XmlReader reader = XmlReader.Create(new StringReader(responseText))) {
while (reader.Read()) { // Parse the xml response body
if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "envelopeId"))
envelopeId = reader.ReadString();
if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "uri"))
uri = reader.ReadString();
}
}
//--- display results
Console.WriteLine("Envelope sent!. EnvelopeId is --> " + envelopeId);
//
// STEP 3 - Get the Embedded Console Sign View
//
// construct another outgoing XML request body
string reqBody = "<recipientViewRequest xmlns=\"http://www.docusign.com/restapi\">" +
"<authenticationMethod>email</authenticationMethod>" +
"<email>" + username + "</email>" + // NOTE: Use different email address if username provided in non-email format!
"<returnUrl>http://www.docusign.com</returnUrl>" + // username can be in email format or an actual ID string
"<clientUserId>1</clientUserId>" +
"<userName>Name</userName>" +
"</recipientViewRequest>";
// append uri + "/views/recipient" to baseUrl and use in the request
request = (HttpWebRequest)WebRequest.Create (baseURL + uri + "/views/recipient");
request.Headers.Add ("X-DocuSign-Authentication", authenticateStr);
request.ContentType = "application/xml";
request.Accept = "application/xml";
request.ContentLength = reqBody.Length;
request.Method = "POST";
// write the body of the request
byte[] body2 = System.Text.Encoding.UTF8.GetBytes (reqBody);
Stream dataStream2 = request.GetRequestStream ();
dataStream2.Write (body2, 0, reqBody.Length);
dataStream2.Close ();
// read the response
webResponse = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(webResponse.GetResponseStream());
responseText = sr.ReadToEnd();
using (XmlReader reader = XmlReader.Create(new StringReader(responseText))) {
while (reader.Read()) { // Parse the xml response body
if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "url"))
url = reader.ReadString();
}
}
Console.WriteLine("Embeded View Result --> " + responseText);
System.Diagnostics.Process.Start(url);
}
catch (WebException e) {
using (WebResponse response = e.Response) {
HttpWebResponse httpResponse = (HttpWebResponse)response;
Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
using (Stream data = response.GetResponseStream())
{
string text = new StreamReader(data).ReadToEnd();
Console.WriteLine(text);
}
}
}
} // end main()
} // end class
} // end namespace
If you haven't already done so, I'd suggest that you review the DocuSign REST API Guide: http://www.docusign.com/sites/default/files/REST_API_Guide_v2.pdf -- as it contains all the information you need to accomplish your goals (in greater detail than I'll describe here).
To create/send an Envelope via the REST API, you'll use POST /accounts/{accountId}/envelopes, as described in the "Send an Envelope or Create a Draft Envelope" section of the API guide. For each recipient whom you'll want to sign embedded/captive within your application, be sure to set the clientUserId property for the recipient -- the presence of this property for a recipient in the Create Envelope request is what tells DocuSign that your application will be initiating/facilitating the signing experience for the Recipient (so DocuSign won't send a signing invitation email to the Recipient).
When it's time for the Recipient to view/sign the Envelope within your application, you'll use POST /accounts/{accountId}/envelopes/{envelopeId}/views/recipient, as described in the "POST Recipient View" section of the API guide -- to retrieve a URL that can be used to launch/initiate the Recipient's DocuSign signing session. Using this URL as the target of an iFrame will present the DocuSign signing session within the frame. In the POST Recipient View request, you set the returnUrl property to indicate where DocuSign should redirect the signer when their embedded/captive signing session is complete. DocuSign will append a querystring parameter ("event") when redirecting to this URL, and the value of that parameter will indicate the outcome of the Signing session. The returnUrl parameter description on page 167 of the API guide lists the possible values of this parameter. Your application (i.e., the redirect page you specify) can interrogate this parameter value to know the outcome of the signing session, and take whatever action is necessary.
Regarding authentication -- the information used to authenticate the Sender of the Envelope is supplied via the X-DocuSign-Authentication header of each API request. Additionally, a specific form of authentication can be specified for each Recipient -- for example, Access Code, Phone Authentication, ID Check, SMS Auth -- you can specify authentication method for each Recipient by setting the appropriate properties for each Recipient in the "Create Envelope" request. (The API Guide contains info about these properties.)
Hey I have the following method
public static string GetShortenedURL(String inURL)
{
String shortURL = "";
String queryURL = "http://api.bit.ly/shorten?version=2.0.1&longUrl=" + inURL + "&login=&apiKey=";
HttpWebRequest request = WebRequest.Create(queryURL) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string jsonResults = reader.ReadToEnd();
int indexOfBefore = jsonResults.IndexOf("shortUrl\": \"") + 12;
int indexOfAfter = jsonResults.IndexOf("\"", indexOfBefore);
shortURL = jsonResults.Substring(indexOfBefore, indexOfAfter - indexOfBefore);
}
return shortURL;
}
Which worked fine on my development machine, but on live server for some reason whenever I call this method I actually seems to visit the URL aswell. The reason why this is a problem is because that URL updates a status of a record. But I only want to do this when the user clicks on the link in the mail but for some very weird reason when Im creating the email on my confirmation page of registration and call this shortened URL method so I can add the short URL in my mail to send out,
it seems to visit it by itself. Hence updating my status when it shouldnt yet.
Any Ideas ?
EDIT : This is how i call it
emailBody.Append(M1Utils.GetShortenedURL(ConfigurationSettings.AppSettings["strSite_FEURL"].ToString() + "login/verify.aspx?" + strEncrypted)).Append("\r\n\r\n");
I am looking for an application that can do the following
a) Programmatically auto login to a page(login.asxp) using HttpWebResponse by using already specified username and password.
b) Detect the redirect URL if the login is successful.
c) Submit another form (settings.aspx) to update certain fields in the database.
The required coding needs to be using asp.net
The application needs to complete this entire process in the same session cookie.
string sUrl = "login.aspx";
HttpWebRequest oRequest = (HttpWebRequest)WebRequest.Create(sUrl);
CookieContainer oMyCookies = new CookieContainer();
oRequest.CookieContainer = oMyCookies;
// encode postdata into byte array. the postdata string format will most likely be different and you'll have to examine the postdata going back and forth using some firefox addon like LiveHTTPHeaders
byte[] oPostData = System.Encoding.UTF8.GetBytes("username=" + HttpUtility.UrlEncode(sUser) + "&pass=" HttpUtility.UrlEncode(sPass));
using (Stream oStream = oRequest.GetRequestStream())
{
oStream.Write(oPostData, 0, oPostData.Length);
}
HttpWebResponse oResponse = oRequest.GetResponse();
// save response cookies in our cookie object for future sessions!
foreach (Cookie oCookie in oResponse.Cookies)
{
oMyCookies.SetCookies(sUrl, oCookie.ToString());
}
// maybe check response headers for location
string sResponseContents = null;
using (StreamReader oReader = new StreamReader(oResponse.GetResponseStream())
{
// store server response into string
sResponseContents = oReader.ReadToEnd();
}
...this is the basic code required for what you want to do.