Category Archives: OAuth

Set Property for List dynamically

How to set proprety for List dynamically.

I have a WebPage class having properties.

strNodeName is one of the property of this class which is the parameters of method.

I want to set the string strTitle according to the parameter strNodeName i.e., set

strTitle = _list[i].Title.ToString();

I want Title to be the strNodeName.

Like if strNodeName = Author, then

strTitle = _list[i].Author.ToString();

if strNodeName = CoAuthor, then

strTitle = _list[i].CoAuthor.ToString(); 

Below is my code.

private void GetGroupedNode(ref TreeNode Node, string strNodeName, int DocumentTypeID)
        {
            WebPage Page = new WebPage();
            List<WebPage> _list = CurrentPage.GetActivePages(_WebSiteID);
 
            TreeNode _AuthorNode;
 
            _AuthorNode = new TreeNode();
 
            // traverse the list to create the tree view
            if (_list.Count > 0)
            {
 
                // set the change in title
                strTitle = _list[i].Title.ToString();
               }
            }
        }

 Thanks 

private void GetGroupedNode(ref TreeNode Node, string strNodeName, int DocumentTypeID)
        {
            WebPage Page = new WebPage();
            List<WebPage> _list = CurrentPage.GetActivePages(_WebSiteID);
  
            TreeNode _AuthorNode = new TreeNode();
            string strTitle = string.Empty;
            // traverse the list to create the tree view
            if (_list.Count > 0)
            {
                for(int i=0;i<_list.Count; i++)
                {
                    // set the change in title
                    if(strNodeName.ToLower() == "title")
                    {
                        strTitle = _list[i].Title.ToString();
                    }
                    else if(strNodeName.ToLower() == "author")
                    {
                        strTitle = _list[i].Author.ToString();
                    }
                    else
                    {
                        strTitle = _list[i].CoAuthor.ToString();
                    }
                }
               }
            }
        }

switch(strNodeName) { case "Title":

would be more readable

TreeNode has name, value property that you can intiailze in the constructor.

[RESOLVED] Facebook Graph API

Hi,

I am usign Graph api for facebook

"error": {
"type": "OAuthException",
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration."
}
}

My Callback_URL  public const string CALLBACK_URL = "http://localhost/FB_Connect/default.aspx";
In my developer Facebookapp:
Site URL
http://localhost:3915/


Please help with this..
Thanks
SC


Hi schalla123,

Here is the same issue as yours, and a solution has been achieved. You can try refer to it :

http://forum.developers.facebook.net/viewtopic.php?id=70773

Hope this help.

I am not sure if facebook can work with localhost as it is not really a specific uri. Try publishing your application to a valid domain and then test for it.

[RESOLVED] Reading an Image into memory stream

Hi Friends,
Please help me with this code. This is what I am trying to do.
Read an image into memory stream and write the Binary data to a database
url = "https://graph.facebook.com/me/albums/?access_token=" + oAuth.Token;
                    json = oAuth.WebRequest(oAuthFacebook.Method.GET, url, String.Empty);
                    Albums albms = js.Deserialize<Albums>(json);
                    foreach (Album alb in albms.data)
                    {
                        alb.picture = "https://graph.facebook.com/" + alb.id + "/picture/?access_token=" + oAuth.Token;
url = "https://graph.facebook.com/me/albums/?access_token=" + oAuth.Token;
                    json = oAuth.WebRequest(oAuthFacebook.Method.GET, url, String.Empty);
                    Albums albms = js.Deserialize<Albums>(json);
                    foreach (Album alb in albms.data)
                    {
                        alb.picture = "https://graph.facebook.com/" + alb.id + "/picture/?access_token=" + oAuth.Token;

                        MemoryStream ms = new MemoryStream(1000);
                            string sfn = alb.picture;
                        System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(alb.picture));
                            m_lImageFileLength = alb.picture.Length;
                            m_barrImg = new Byte[Convert.ToInt32(m_lImageFileLength)];
                            
                            ms.Read(m_barrImg, 0, (int)m_lImageFileLength);
                            //Basically I want to read this alb.picture into a memory stream, instead of storing it on the local harddisk
and write the binary data into DB.
                         insert_Facebook_Photos(Convert.ToInt64(ui.id), m_barrImg, alb.created_time.ToString(), alb.updated_time.ToString());
                         fs.Close();



 

private Image GetRemoteImage(string filePath)
{
 WebClient webClient = new WebClient();
byte[] imageBytes = webClient .DownloadData(filePath);
    MemoryStream mem = new MemoryStream(imageBytes);
   return Image.FromStream(mem);
}

To download a remote image you need to use HttpWebRequest of WebClient .Both classes are in System.Net namespace

Try below code

 

@Shakti Singh: Why should I use Web Client

I have my code like this

MemoryStream ms = new MemoryStream(1000);
                            string sfn = alb.picture;
                           
                            //FileInfo filImage = new FileInfo(sfn);
                            m_lImageFileLength = alb.picture.Length;
                            m_barrImg = new Byte[Convert.ToInt32(m_lImageFileLength)];
                            
                            ms.Read(m_barrImg, 0, (int)m_lImageFileLength);
                            
                            objBLL.insert_FacebookPhots(Convert.ToInt64(ui.id), m_barrImg, alb.created_time.ToString(), alb.updated_time.ToString());
                            
But here it is just inserting s 0x000000000000000000000000000. and not any image

Thanks

Smitha

Your memorystream contain no data..Since file is present on remote location) as url suggests you need to download it and save that in memory stream then from memory stream you can save it back to db

 

alb.picture = "https://graph.facebook.com/" + alb.id + "/picture/?access_token=" + oAuth.Token; // This is just a URL
 
                        MemoryStream ms = new MemoryStream(1000);
                            string sfn = alb.picture;
                  //      System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(alb.picture)); //This way you were retriving image only then you will have image bytes


 ms.Read(m_barrImg, 0, (int)m_lImageFileLength); //This is nothing but an empty byte array