I'm trying to get user info using the FacebookSDK, but its not working.
This is what i try to do:
var fb = new FacebookClient("my_access_code");
dynamic result = fb.Get("me");
var name = result.name;
MessageBox.Show("Hi " + name);
This is not working, because fb hase no get method. But every tutorial and code snippets i looked at are using get.
Is this code deprecated? If this is whats the new method of getting info?
So, as we established in the comments - for Windows Phone 8 there are async calls that should be used instead of the old Get call. That's why you're not seeing the Get call, but the GetTaskAsync call. For this simple example, you use it the same way
dynamic result = await fb.GetTaskAsync("me");
var name = result.name;
MessageBox.Show("Hi " + name);
Other examples may vary. More about async calls with Facebook C# can be found in the official documentation, but that's not exactly for the Windows Phone 8, but Windows Phone 7 which used a different async pattern. Still, it may be helpful to you. There's a link to a supposedly more updated documentation for async/await calls but for some reason I'm seeing a 'Page not found' error.
try this instead
var fb = new FacebookClient("my_access_code");
dynamic result = await fb.GetTaskAsync("/me");
var name = result.name;
MessageBox.Show("Hi " + name);
Related
I'm attempting to get the characteristics of a custom BLE service. I have a NETStandard class library, making use of NETCore build 17134 for Bluetooth communication. This library is then used in a WPF application (.NET Framework 4.7.1.) I'm able to connect to my BLE peripheral, as well as read the generic service that includes Hardware Revision, etc. However, when it then goes to get the characteristics of my custom service, the status reads AccessDenied and the array of characteristics is empty. Any help would be greatly appreciated.
The same code works when it's purely UWP. However, I have no way to set Bluetooth permissions in the desktop app as I can in UWP. I've attempted running as administrator and performing the workaround using an AppID/registry entry. It didn't seem to work, but perhaps I simply did something wrong.
Is this a known issue? I've read there's been some regression since the original Creator's Update (15xxx) but the threads all seem about a year old.
protected async override Task<IList<ICharacteristic>> GetCharacteristicsNativeAsync()
{
var accessRequestResponse = await _nativeService.RequestAccessAsync();
// Returns Allowed
if (accessRequestResponse != Windows.Devices.Enumeration.DeviceAccessStatus.Allowed)
{
throw new Exception("Access to service " + _nativeService.Uuid.ToString() + " was disallowed w/ response: " + accessRequestResponse);
}
var allCharacteristics = await _nativeService.GetCharacteristicsAsync(Windows.Devices.Bluetooth.BluetoothCacheMode.Uncached);
// Status: AccessDenied
var status = allCharacteristics.Status;
// No error
var err = allCharacteristics.ProtocolError;
var nativeChars = allCharacteristics.Characteristics;
var charList = new List<ICharacteristic>();
foreach (var nativeChar in nativeChars)
{
var characteristic = new Characteristic(nativeChar, this);
charList.Add(characteristic);
}
return charList;
}
Any help would be greatly appreciated!
I'm having a very hard time with what I feel should be a simple task. Every week, our team queries VMware vCenter for three pieces of output: VM counts in three different locations. Here is what it looks like:
Name Value
---- -----
locationA 1433
locationB 278
locationC 23
The information is emailed to our team, as well as some of the higher-ups who like to see the data. This is all automated with a Powershell script and Windows Task Scheduler running on a server, no problems.
That data is also placed in a Google sheet. We just append a new row with the date, and copy and paste the data into the three existing columns. It takes 30 seconds, once a week. Seems silly given how little time it takes to copy it over to the Google sheet but I really want to automate that last process using Google Sheets API.
I seem to keep finding and persuing what feel are online wild goose chases, in the Google scripting to accessing and editing Google sheets. I've downloaded and installed the Sheets API libraries, Drive API libraries, the Google .net library, set up the Google developer site, and run through the Google sheets API documentation and OAuth authenticating. I'm using Visual Studio 2013 because I figured that would play the best with Powershell and calling the .net commands.
I have pretty much no coding experience outside of Powershell (if you can call that coding). I can't even figure out how to pull the Google sheet, much less do anything to it. Nothing I've tried is working so far, and for what little time it takes to copy this info manually every week I've already spent so much more time than is probably worth it. I feel like if I can get a handle on this, that would open the door for further Google automation in the future since we operate with a Google domain. At any rate, help is very much appreciated.
Here is my latest scripting attempt in Visual Studio:
using System;
using Google.GData.Client;
using Google.GData.Spreadsheets;
namespace MySpreadsheetIntegration
{
class Program {
static void Main(string[] args)
{
string CLIENT_ID = "abunchofcharacters.apps.googleusercontent.com";
string CLIENT_SECRET = "secretnumber";
string REDIRECT_URI = "https://code.google.com/apis/console";
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.ClientId = CLIENT_ID;
parameters.ClientSecret = CLIENT_SECRET;
parameters.RedirectUri = REDIRECT_URI;
parameters.Scope = SCOPE;
string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
Console.WriteLine(https://code.google.com/apis/console);
Console.WriteLine("Please visit the URL above to authorize your OAuth "
+ "request token. Once that is complete, type in your access code to "
+ "continue..."));
parameters.AccessCode = Console.ReadLine();
OAuthUtil.GetAccessToken(parameters);
string accessToken = parameters.AccessToken;
Console.WriteLine("OAuth Access Token: " + accessToken);
GOAuth2RequestFactory requestFactory =
new GOAuth2RequestFactory(null, "MySpreadsheetIntegration-v1", parameters);
SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");
service.RequestFactory = requestFactory;
var driveService = new DriveService(auth);
var file = new File();
file.Title = "VSI - VM Totals by Service TEST";
file.Description = string.Format("Created via {0} at {1}", ApplicationName, DateTime.Now.ToString());
file.MimeType = "application/vnd.google-apps.spreadsheet";
var request = driveService.Files.Insert(file);
var result = request.Fetch();
var spreadsheetLink = "https://docs.google.com/spreadsheets/d/GoogleDoc_ID";
Console.WriteLine("Created at " + spreadsheetLink);
End Class;
End Namespace;
}
}
}
For anyone still following this, I found a solution. I was going about this entirely the wrong way (or at least a way that I could comprehend). One solution to my issue was to create a new Google Script that only accessed my email once a week (after we got the report) and teased out everything but the data I was looking for and sent it to the Google spreadsheet.
Here's the script:
function SendtoSheet(){
var threads = GmailApp.search("from:THESENDER in:anywhere subject:THESUBJECTOFTHEEMAILWHICHNEVERCHANGES")[0];
var message = threads.getMessages().pop()
var bodytext = message.getBody();
counts = []
bodytext = bodytext.split('<br>');
for (var i=0 ; i < bodytext.length; i++){
line = bodytext[i].split(':');
if (line.length > 0){
if (!isNaN(line[1])){counts.push(line[1]);}}}
var now = new Date()
counts.unshift(Utilities.formatDate(now, 'EST', 'MM/dd/yyyy'))
var sheet = SpreadsheetApp.openById("GoogleDocID")
sheet = sheet.setActiveSheet(sheet.getSheetByName("Data by Week"))
sheet.appendRow(counts)
}
That Counts array contains the magic to extract the numeric data by breaking up by line breaks and :'s. Works perfectly. It didn't involve figuring out how to use Visual Studio, or the .net Google libraries, or editing the running PowerShell script. Clean and easy.
Hope this helps someone.
I was wondering if it's possible to call the default navigation application within my Windows Phone 8.1 application. I have an address and I would like for the user to press a button and be able to navigate to that address through the default navigation app. If this is possible, how do I do it?
Thanks for your time,
Johan
You can launch turn-by-turn directions apps using the ms-drive-to and ms-walk-to schemes (depending on the type of directions you want) but you first need to get a geocoordinate for the address that you have. Since you're targeting Windows Phone 8.1, you can use the MapLocationFinder class in the Windows.Services.Maps namespace.
string locationName = "Empire State Building";
string address = "350 5th Avenue, New York City, New York 10018";
var locFinderResult = await MapLocationFinder.FindLocationsAsync(
address, new Geopoint(new BasicGeoposition()));
// add error checking here
var geoPos = locFinderResult.Locations[0].Point.Position;
var driveToUri = new Uri(String.Format(
"ms-drive-to:?destination.latitude={0}&destination.longitude={1}&destination.name={2}",
geoPos.Latitude,
geoPos.Longitude,
locationName));
Launcher.LaunchUriAsync(driveToUri);
the official solution is:
Uri uri = new Uri("ms-drive-to:?destination.latitude=" + latitude.ToString(CultureInfo.InvariantCulture) +
"&destination.longitude=" + longitude.ToString(CultureInfo.InvariantCulture))
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
// Uri launched.
}
else
{
MessageBox.Show("error");
}
But, there is a problem with this solution.
If you use the nokia programs (HERE), it works fine.
if you want to use waze, you have to add origin.latitude and origin.longitude.
in the MSDN page, They said that it is not necessary, but in fact, you have to write it.
I am already not enable to load moovit but if someone has an issue, it'll help me a lot.
[ My humble request: please don't ignore this question just by adding some reference question link. I read all the reference i can, but i didnt get what i need]
I am trying to make a windows/console application where i need to access the user details offline. So i tried the following code.
String finalRedirectUri = "https://www.facebook.com/dialog/oauth?client_id=" +
_appKey2 + "&redirect_uri=" + _SiteURL + "&scope=email,read_stream";
String GraphUri = "https://graph.facebook.com/oauth/access_token?client_id=" +
_appKey2 + "&redirect_uri=" + _SiteURL + "&scope=email,read_stream";
FacebookClient client = new FacebookClient(_appKey2, _secret2);
FacebookOAuthClient oAuthClient =
new FacebookOAuthClient(FacebookApplication.Current);
oAuthClient.AppId = _appKey2;
oAuthClient.AppSecret = _secret2;
oAuthClient.RedirectUri = new Uri(finalRedirectUri);
String Uri = oAuthClient.GetLoginUrl().ToString();
try
{
dynamic tokenResult =
oAuthClient.ExchangeCodeForAccessToken("offline_access");
}
catch (Exception exp)
{
MessageBox.Show("" + exp.Message);
}
I am always getting error message: " (OAuthException) Invalid verification code format"
I searched many links in stackoverflow and http://developers.facebook.com/docs/authentication/ also but it didnt helped me to find the solution. I dont even know which uri to use.
I am using Visual Studio 2010 [ Please donot simply ignore this question just by marking as duplicate]
Be gentle to me please..
It's possible that if you downloaded the compiled facebook dll (from NuGet for example), that it's badly built. Try downloading the source and compiling it yourself and using that dll.
Here is an example of a post with the same problem.
note even though their problem is giving a different error, it's possible this is precisely the problem you have, as it's in the same function your variant may just be running into another one of their mistakes.
here are two other possible problems you may be having:
Sometimes, redirect uri should be null
OAuth really likes the '/' at the end of a uri
is it possible to display the revision/build number in the webservice description?
I want the users to see what version that is currently up and running when they go to the url for the webservice.
Ex.
[WebService(Namespace = "http://webservice.mydomain.com/", Name = "webservice for multimedia devices", Description = "Last build: **xxxxx**")]
I want to get it dynamically if possible (System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString())
I also tried this (suggestion see below). This got the description but it could not update it before it showed the webservice to the client.
var t = typeof(webClient);
var att = (WebServiceAttribute)t.GetCustomAttributes(typeof(WebServiceAttribute), true)[0];
att.Description = "Current running version: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
I haven't verified it, but try this:
WebServiceAttribute att = (NamespaceAttribute)t.GetCustomAttributes(WebServiceAttribute))[0];
att.Description = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
This has to be done at some suitable point during startup.
You can, but you need to manually define the assembly info and version first, then use Reflection to get it back out at runtime. By default, there doesn't seem to be a concept of a "version #" for an ASP.NET app unless you define it yourself.
This article shows how to do it. The article shows how to get a lot more than just the version #, but it's in there.
http://wiki.lessthandot.com/index.php/ASP.NET:_Display_Version_Information