Trying to implement the new SnapChat Creative Kit in Xamarin.iOS, I bound the SDK framework using Objective Sharpie. While following the official documentation (which only has implementation steps for swift and obj-c) for other SDKs wan not a problem - I successfully implemented Login Kit - I came to a stumble with this code while trying to send the content to SnapChat.
In particular, in the Documentation, to send the contents to the api, this code is used:
// swift
let snapImage = /* Set your image here */
let photo = SCSDKSnapPhoto(image: snapImage)
let snap = SCSDKSnapPhotoContent(snapPhoto: photo)
let api = SCSDKSnapAPI(content: snap)
api.startSnapping({ (error: Error?) in
/* Error handling */
})
According to the docs,
SCSDKPhotoSnapContent is an implementation of the SCSDKSnapContent protocol. It provides a way to model a photo Snap for sharing to Snapchat.
Here is my C# implementation:
var snapImage = GetCurrentScreenImage();
SCSDKSnapPhoto photo = new SCSDKSnapPhoto(snapImage);
SCSDKPhotoSnapContent snapPhoto = new SCSDKPhotoSnapContent(photo)
SCSDKSnapAPI api = new SCSDKSnapAPI(snapPhoto);
api.StartSnappingWithCompletionHandler((NSError error) =>
{
// Error handling
});
The problem is SCSDKSnapAPI constructor only accepts SCSDKSnapContent, which is an abstract class, and not its implementation, and I get an error calling it:
CS1503 Argument 1: cannot convert from 'SCSDKCreativeKit_Bindings.SCSDKPhotoSnapContent' to 'SCSDKCreativeKit_Bindings.SCSDKSnapContent'
EDIT:
ApiDefinition.cs
[Export("initWithContent:")]
IntPtr Constructor(SCSDKSnapContent content);
I tried adding another constructor like this:
[Export("initWithContent:SCSDKPhotoSnapContent")]
IntPtr Constructor(SCSDKPhtotoSnapContent content);
The code now builds, but I receive the following error code from SnapChat on callback:
SnapEncryptionMetadataUnexpectedStatusCode
I couldn't find a way to correctly implement SCSDKSnapContent in Xamarin.iOS. I did find a workaround, that sort of works. If you change constructor for SCSDKSnapAPI in the binding library from SCSDKSnapContent to one of its implementations (SCSDKPhotoSnapContent in my case), like this:
[Export("initWithContent:")]
IntPtr Constructor(SCSDKPhotoSnapContent content);
You can then correctly call SCSDKSnapAPI in Xamarin
var snapImage = GetCurrentScreenImage();
SCSDKSnapPhoto photo = new SCSDKSnapPhoto(snapImage);
SCSDKPhotoSnapContent snapPhoto = new SCSDKPhotoSnapContent(photo)
SCSDKSnapAPI api = new SCSDKSnapAPI(snapPhoto);
api.StartSnappingWithCompletionHandler((NSError error) =>
{
// Error handling
});
Related
I am trying to upgrade my c# programs to VersionOne.SDK.API version 15.3.0.0. I am getting a message that VersionOneAPIConnector is obsolete and that I should use V1Connector instead. When the ObjectModel API was discontinued, I had changed to doing everything with VersionOneAPIConnector using query.v1 (using HttpPost) and rest-1.v1/Data(using SendData). After getting the new version, I figured out how to use V1Connector and pass it to Services and then to use ExecutePassThroughQuery() to pass what had been the 2nd argument to HttpPost for my query.v1 code like this:
Original code:
Stream resultStream = _cx.HttpPost("/query.v1", System.Text.Encoding.UTF8.GetBytes(GetQueryForMembers()));
using (StreamReader reader = new StreamReader(resultStream, Encoding.UTF8))
{
result = reader.ReadToEnd();
}
New Code:
result = _service.ExecutePassThroughQuery(GetQueryForMembers());
Where GetQueryforMembers() is:
public static string GetQueryForMembers()
{
return #"
from: Member
select:
- Email
where:
AssetState: Active";
}
But, I can't figure out how to use V1Connector/IServices for my rest/SendData code. All the Rest examples on the VersionOne site now show using it from the API Console, not from stand-alone code. It looks like at least some of the things I was doing with Rest can be done via Services.executeOperation() or Services.Meta, but the V1 employee that I was working with to get rid of my Object Model code a few years ago had recommended only using the API for the connection and to otherwise use Rest and Query, so that I didn't have to worry about compatibility with .NET versions. But, from looking at the examples currently provided and the functionality available on the V1Connector/IServices classes, it looks like maybe V1 wants us to use Meta API rather than REST now? Or is there a way to use REST directly that I am missing? From looking at the source, I see there is an internal UseDataAPI() on the V1Connector that IServices uses. But, it only uses it in Save, ExecuteOperation and Retrieve and it doesn't look like any of those do what I'm trying to do.
This is an example, if what I was doing before with REST (where _passed_cx is a VersionOneAPIConnector)
string newDefect = string.Concat("<Asset href=\"/MentorG01/rest-1.v1/New/Defect\">",
"<Attribute name=\"Name\" act=\"set\">", cdata_attribute_value, "</Attribute>",
"<Relation name=\"Scope\" act=\"set\">",
"<Asset href=\"/MentorG01/rest-1.v1/Data/Scope/", project_oid.Split(':')[1], "\" idref=\"", project_oid, "\" />",
"</Relation>",
"</Asset>");
string url = "rest-1.v1/Data/Defect";
Stream resultStream = _passed_cx.SendData(url, newDefect);
Anyone know how to use rest-1.v1 with V1Connector? If so, can you provide an example?
I am attempting to perform some basic integration using Acumatica's web services. Unfortunatly, I'm having problems logging in. According to their documentation, this process should look something like:
apitest.Screen context = new apitest.Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.AllowAutoRedirect = true;
context.EnableDecompression = true;
context.Timeout = 1000000;
context.Url = "http://localhost/WebAPIVirtual/Soap/APITEST.asmx";
LoginResult result = context.Login("admin", "E618");
Simple enough. However, after creating and importing a WSDL file from Acumatica into Visual Studio, I found I don't have a Screen object. I do, however have a ScreenSoapClient object, which has a similar Login() method.
ScreenSoapClient context = new Acumatica.ScreenSoapClient("ScreenSoap");
LoginResult result = context.Login("username", "password");
That part works. In fact, the LoginResult give me a session ID. However, if I try to make any calls to the service, such as:
CR401000Content cr401000 = context.CR401000GetSchema();
I get an error: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> PX.Data.PXNotLoggedInException: Error #185: You are not currently logged in.
While the version of Acumatica we're using does appear to be slightly newer, I'm unsure why the Screen() object isn't available. Consequently, if I try a bad username/password, Login() does fail (as it should). From what I can the tell, the ScreenSoapClient class is using service model details from web.config, so it's getting the endpoint address and other details there.
Is there something I'm missing or doing wrong?
As i see, you use WCF to create your service reference.
So you should enable cookies in service binding:
var binding = new BasicHttpBinding()
{
AllowCookies = true
};
var address = new EndpointAddress("http://localhost/WebAPIVirtual/Soap/APITEST.asmx");
var c = new ServiceReference1.ScreenSoapClient(binding, address);
Or, you can use old asmx web service reference (http://msdn.microsoft.com/en-us/library/bb628649.aspx).
Then everything will be same as in Acumatica`s documentation.
As noted in a comment above, I was able to make contact with a representative from Acumatica. He had me remove then recreate the service references in our project and try again. That apparently did the trick and the "Error #185: You are not currently logged in" error went away.
I am using official Facebook .NET SDK for publish music.listens action by below code.
var result = facebook.Post("me/music.listens", new
{
song = new
{
type = "music.song",
url = "www.example.com/blabla",
title = "Womanizer",
image = "www.example.com/blabla",
description = "Bu kısma açıklama gelecek",
musician = new
{
type = "profile",
title = "Britney Spears",
image = "www.example.com/blabla",
url = "www.example.com/blabla",
description = "Here is great song"
}
}
})
This code publish listen activity as below format.
"John listened to Womanizer on MySiteName."
But Pandora.com publish that activity with Artist information as below format.
"John listened to Womanizer by Britney Spears on Pandora."
This format is what i expected. It also shows tooltip on Artist name by showing Artist photo and with description. For that reason i passed musician information in parameters But Facebook looks ignore that parameter.
How can i represent music listen action as it is Pandora does or what is wrong on passed parameters ?
I have not used the official .NET SDK to do what you are doing, however I have used direct HTTP POST calls to do this. The Facebook Open Graph requires a "reference object" for the song and musician objects instead of passing the data as parameters. These "reference objects" are just web pages with special meta-data.
In my situation I have a web server that hosts the song and musician meta-data in the Facebook Open Graph formats as described in their documentation. Then I made a me/music.listens post passing the url for the song and the url for the musician.
So instead of passing all the raw data as parameters, you need a web site which hosts all the meta-data.
If you look at the documentation here you will see some examples
https://developers.facebook.com/docs/reference/opengraph/action-type/music.listens
If you go to http://samples.ogp.me/461258627226537 and view the source you can see a sample meta data for the song.
For example here is their php sample (sorry they don't have .NET samples)
/* make the API call */
$response = $facebook->api(
"/me/music.listens",
"POST",
array (
'song' => 'http://samples.ogp.me/461258627226537',
'musician' => 'http://samples.ogp.me/390580850990722',
)
);
/* handle the result */
I am attempting to use the Google CustomSearch API for .NET using sample code from the following locations:
Steps for using Google custom search API in .NET
How can I do a search with Google Custom Search API for .NET?
http://astrocoder.com/search-using-google-custom-search/
The basic code in it's simplest form looks like:
string apiKey = "my-api-key";
string cseKey = "my-cse-id";
string query = "search query";
var bcsi = new BaseClientService.Initializer { ApiKey = apiKey };
var css = new CustomsearchService(bcsi);
var listRequest = css.Cse.List(query);
listRequest.Cx = cseKey;
Search search = listRequest.Fetch();
However, when I attempt to compile this, I am getting the following error:
'Google.Apis.Customsearch.v1.CseResource.ListRequest' does not
contain a definition for 'Fetch' and no extension method 'Fetch'
accepting a first argument of type
'Google.Apis.Customsearch.v1.CseResource.ListRequest' could be found
As far as I can tell, I have all of the required library files (I used NuGet to install the Google APIs). When I view the API documentation, I do not see a Fetch() method, however, all of the sample code I have been able to find shows the listRequest.Fetch() method call.
https://developers.google.com/resources/api-libraries/documentation/customsearch/v1/csharp/latest/classGoogle_1_1Apis_1_1Customsearch_1_1v1_1_1CseResource_1_1ListRequest-members.html
Instead of using Fetch() you can use the following.
Search search = listRequest.Execute();
The fetch() api has been replaced after version 1.4 but the sample code has not been updated yet.
I'm starting to work with Rally .NET API, in order to develop a plugin to import User Story into Enterprise Architect.
I have started by the examples in the following page: http://developer.help.rallydev.com/rest-api-net.
In the last one, for example, I got this errors:
//Create an item
DynamicJsonObject toCreate = new DynamicJsonObject();
toCreate["Name"] = "My Defect";
CreateResult createResult = restApi.Create("defect", toCreate);
Error 1 No overload for method 'Create' takes 2 arguments
//Delete the item
OperationResult deleteResult = restApi.Delete(createResult.Reference);
Error 2 No overload for method 'Delete' takes 1 arguments
But the documentation here is different from the examples.
All in all, I would like to know any good sources of information to learn this Rally API and which is the correct implementation for the Create and Delete in the examples of the first page.
Thanks in advance,
Pedro
Sorry for the confusion - with the latest release of the .NET REST DLL (version 1.0.15), both the Create and Delete methods changed slightly - they now require a Workspace Ref:
String workspaceRef = "/workspace/12345678910";
DynamicJsonObject toCreate = new DynamicJsonObject();
toCreate["Name"] = "My Defect";
CreateResult createResult = restApi.Create(workspaceRef, "defect", toCreate);
Delete should look like this:
OperationResult deleteResult = restApi.Delete(workspaceRef, createResult.Reference);
Or this:
myDefectObjectID = "12345678911";
OperationResult deleteResult = restApi.Delete(workspaceRef, "Defect", myDefectObjectID);
We'll work to get the documentation updated as quickly as possible. Thanks for pointing this out!