Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.NET webpage as Facebook app

Posted on 2011-03-15
7
Medium Priority
?
923 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
ID: 35136861
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
ID: 35138729
Another Very good Converter
http://www.icsharpcode.net/opensource/sd/
0
 

Author Comment

by:VikingOnline
ID: 35140338
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:VikingOnline
ID: 35140384
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 2000 total points
ID: 35140411
See here for the library
http://facebooknet.codeplex.com/
0
 
LVL 2

Expert Comment

by:enkor
ID: 35141908
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
ID: 35162300
Thank you for your help and links!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Suggested Courses

926 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