Solved

ASP.NET webpage as Facebook app

Posted on 2011-03-15
7
916 Views
Last Modified: 2012-05-11
Hey guys,
I have another question with more down the line questions, but I suddenly realized I was struggling to just get my asp.net web page written in vb to be setup as a Facebook application.

I have seen many links with "how to", but they are mostly meant for php or if for asp.net it's written in C# and I'm struggling to get this converted to vb.

I believe another option for how to integrate your site is by using JS. But I'm not any good with JS, but if asp.net is not a good interface as it's mostly php for Facebook, then maybe JS is an alternative?

Does anyone have any good links, info, SDK, examples etc. for setting up a Facebook application in asp.net with VB as the language?

Thanks!
Ronny
0
Comment
Question by:VikingOnline
7 Comments
 
LVL 8

Expert Comment

by:tiagosalgado
Comment Utility
If you have what you want in C# code, you maybe want to convert it to VB.NET using a converter.

http://www.developerfusion.com/tools/convert/vb-to-csharp/
http://converter.telerik.com/
0
 
LVL 20

Expert Comment

by:hes
Comment Utility
Another Very good Converter
http://www.icsharpcode.net/opensource/sd/
0
 

Author Comment

by:VikingOnline
Comment Utility
I'll try to convert, but of course it might have been much easier to read and understand in vb.

So I get a few error messages while trying to follow this guide with C#
http://www.datasprings.com/resources/articles-information/developing-with-facebook-api-sdk-w-asp.net

I loaded the facebook.dll (basically all the files given in the /bin directory). As far as I understand there are no issues with referencing a C# .dll from vb.net code.

I converted and used the following code:

 
Imports System
Imports System.Configuration
Imports System.Web
Imports System.Web.UI
Imports facebook
Imports System.Collections.Generic
Imports System.Xml.Linq


Partial Class _Default
    Inherits System.Web.UI.Page

    protected facebook.Components.FacebookService _fbService = new facebook.Components.FacebookService()

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'Set the values for our Facebook service object's properties from our
        'web config file constants(specific to our application).        
        _fbService.ApplicationKey = ConfigurationManager.AppSettings["AppKey"]
        _fbService.Secret = ConfigurationManager.AppSettings["Secret"]
        _fbService.IsDesktopApplication = Convert.ToBoolean(ConfigurationManager.AppSettings["Desktop"])

        Try
            Dim sessionKey As String = TryCast(Session("facebook_session_key"), [String])
            Dim userId As String = TryCast(Session("facebook_userId"), [String])

            ' will will have the auth_token in the query params
            Dim authToken As String = Request.QueryString("auth_token")

            'We have already established a session on behalf of this user
            If Not [String].IsNullOrEmpty(sessionKey) Then
                _fbService.SessionKey = sessionKey

                _fbService.uid = Convert.ToInt64(userId)
                ' This will be executed when Facebook login redirects to our page
            ElseIf Not [String].IsNullOrEmpty(authToken) Then
                _fbService.CreateSession(authToken)
                Session("facebook_session_key") = _fbService.SessionKey
                Session("facebook_userId") = _fbService.uid.ToString()
                Session("facebook_session_expires") = _fbService.SessionExpires

            End If
        Catch ex As Exception
            lblUserName.Text = ex.Message.ToString()
        End Try


    End Sub

Open in new window



1st error message:
     
      Imports facebook

"Namespace or type specified in the Imports 'facebook' doesn't caontain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases."

I would have thought that was an error message you would get if you did not reference the .dll, but I have done that. At least facebook.dll and facebook.dll.refresh and facebook.xml are all available in the \bin\ in the solution explorer.


2nd error message:

     protected facebook.Components.FacebookService _fbService = new facebook.Components.FacebookService()

"End of statement expected."
Not sure if this is just written wrong, or if once the import reference is working this will be OK.

3rd error message:

     _fbService.ApplicationKey = ConfigurationManager.AppSettings["AppKey"]

By _fbService:
"'_fbService' is not declared. It mayb e inaccessible due to its protection level."
This error message should be OK once the statement in error message 2 is OK. _fbService = new.......

By ["     before AppKey:
"Identifier expected"
This error I'm more unsure about. I thought I was referencing to the AppKey that is hidden inside the web.config file, but maybe I'm doing this wrongly.


Anyone that knows what I'm doing wrong here? If it's something I convert wrong, or if I do something fundamentally wrong, or if I should follow one of the other page suggestions for how to connect to Facebook?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:VikingOnline
Comment Utility
Forgot to increase the points at the same time..
I thought someone would have a page reference and just post a asp.net in vb guide that I would read and follow through. But with so long without any Facebook link and trying to do conversion and getting error messages, this seems to be a much harder question than I first thought.
0
 
LVL 20

Accepted Solution

by:
hes earned 500 total points
Comment Utility
See here for the library
http://facebooknet.codeplex.com/
0
 
LVL 2

Expert Comment

by:enkor
Comment Utility
Hi Viking,
watch on Facebook.com/developers on JS SDK. Do not be affraid.

There are some easy steps to do it instead of you:
Use their FBML tags. It will render the component you want. If you dont want to see any component, but just for example to post messages to a FB wall, you must setup the FB application for your domain and then generate access token. (Insert to your page FB login button, and catch the responsed info. You can easily see all necessary variables.)

Better will by, if you tell, what exactly you want to do in your app.
0
 

Author Comment

by:VikingOnline
Comment Utility
Thank you for your help and links!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now