开发者

Create an instance of FacebookApp programically using AppID, Secret and Key

开发者 https://www.devze.com 2023-02-07 15:43 出处:网络
How can I i开发者_开发技巧nstantiate the FacebookApp with custom AppID/Key/Secret without using the web.config?

How can I i开发者_开发技巧nstantiate the FacebookApp with custom AppID/Key/Secret without using the web.config?

I need to do this due to multilingual Facebook applications with several tab-pages within one Visual Studio solution. Since Facebook can only have one Tab-page for each application I'm forced to figure this out.


You can use the right constructor for the job:

public FacebookApp(IFacebookSettings settings)

The settings object can be constructed this way:

var settings = new FacebookSettings
{
    ApiKey = //[Your key]
    ApiSecret = //[Your secret]
    AppId = //[Your appid]
}

Complete code:

var fbSettings = new FacebookSettings
{
    ApiKey = //[Your key]
    ApiSecret = //[Your secret]
    AppId = //[Your appid]
}
var fb = new FacebookApp(fbSettings);


Fuzzy,

Carlos is correct.

Are you doing MVC or Classic WebForms? This is exactly what you would do if you were doing WebForms (you would probably want to store this in some common base page, but beyond that his solution is absolutely correct.

With MVC it is just a matter of getting things set up properly. You can do this within a Base Controller. You might want to study how things get wired up in the source code of the Facebook C# SDK to get a better picture (I'm thinking I need to build a sample for this in the SDK's samples)


If you are using the new v5.x of the Facebook C# SDK we have made it a lot easier to set Facebook settings without using config files.

There is a new interface called IFacebookApplication. Create a custom class and implement the IFacebookApplication interface.

Then you can change the default application settings by

FacebookContext.SetApplication( iFacebookApplication );

To retrieve the current application setting you would:

var fbAppSettigns = FacebookContext.Current;
0

精彩评论

暂无评论...
验证码 换一张
取 消