Problem mit einer API welche selbst kompilliert werden muss

  • C#
  • .NET (FX) 4.5–4.8

Es gibt 5 Antworten in diesem Thema. Der letzte Beitrag () ist von Radinator.

    Problem mit einer API welche selbst kompilliert werden muss

    Hallo Liebe Community,

    Ich habe ein Problem worum ich mich eigentlich nicht Kuemmern Muesste wenn dieser Api Entwickler die dll. einfach als Release Bereitstellen wuerde :cursing: , anstelle muss ich jetzt seine Api selber Kompillieren.

    Da ich mich noch nicht wirklich mit dem Wissen welches dieser Code nutzt befasst habe, weiss ich leider absolut nicht was ich hier machen Muss.
    Die Api nutzt eine andere API namens "Flurl", welche ich auch bereits importiert habe, nur zeigt er mir jetzt noch ein Paar fehler An (Welche alle der gleiche fehler sind, nur halt mehrfach)

    Der Fehler Lautet:
    Cannot implicitly convert type 'Flurl.Http.IFlurlClient' to 'Flurl.Http.FlurlClient' An explicit conversion exists (are you missing a cast?)


    Der Code in dem Die Fehler Auftreten:
    Spoiler anzeigen

    Extensions/Utilities.cs

    C#-Quellcode

    1. if (headers != null)
    2. fc = fc.WithHeaders(headers); // Fehler
    3. if (cookies != null)
    4. fc = fc.WithCookies(cookies); // Fehler
    5. if (!string.IsNullOrEmpty(oAuthToken))
    6. fc = fc.WithHeader("Authorization", new AuthenticationHeaderValue("Bearer", oAuthToken)); // Fehler
    7. return fc.AllowAnyHttpStatus();


    API/User.cs

    C#-Quellcode

    1. FlurlClient fc = new FlurlClient("https://us-gmsg.np.community.playstation.net/groupMessaging/v1/messageGroups")



    Falls Jemand so nett Sein wuerde und mir da Helfen koennte waere ich Sehr froh.

    Die Api die Ich nutzen Moechte Kann man hier finden:
    github.com/Tustin/psn-csharp

    Es Frustriert mich naemlich ehrlich gesagt sehr, dass ein Entwickler Eine Api schreibt, auf Github sogar schreibt dass man die Kompillierte dll bei den Releases herunterladen kann, und wenn man dann schaut, sind die Releases Leer.

    Ich habe den Entwickler auch schon seit mehreren Tagen auf so gut wie allen Plattformen geschrieben, nur leider Antwortet er mir nicht daher seit ihr Meine Letzte Hoffnung meine Neue Idee nicht ins Wasser Planschen zu Lassen.

    lg
    Begeisterter BF4 Spieler :D

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „Gangsterkrafter“ ()

    [Spekulatiusmodus]
    fc.WithHeaders(headers) gibt wohl etwas vom Typ IFlurlClient wieder (falls man der Namensgebung mit dem führenden "I" glauben darf, könnte das zwar ein Interface sein, aber besser selbst prüfen, ob das wirklich ein Interface ist), Du willst das aber in eine Variable vom Typ FlurlClient packen. Was passiert denn, wenn Du n DirectCast von fc.WithHeaders(headers) in FlurlClient machst? Keine Ahnung, ob das was wird, aber vielleicht reicht das ja schon. Denn wenn der andere Option Strict Off programmiert hat (falls das da überhaupt möglich sein sollte), würde beim Erstentwickler vielleicht eine automatische Umwandlung stattfinden.
    [/Spekulatiusmodus]
    Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von „VaporiZed“, mal wieder aus Grammatikgründen.

    Aufgrund spontaner Selbsteintrübung sind all meine Glaskugeln beim Hersteller. Lasst mich daher bitte nicht den Spekulatiusbackmodus wechseln.
    Habe Mich Leider etwas vertan, tut mir leid, ist kein Visual Basic sondern C# -.-

    Alte gewohnheiten halt.

    Die Komplette Utitlities.cs: (fehler ab zeile 32)
    Spoiler anzeigen

    C#-Quellcode

    1. using Flurl;
    2. using Flurl.Http;
    3. using System.Collections.Generic;
    4. using System.Dynamic;
    5. using System.Net.Http;
    6. using System.Net.Http.Headers;
    7. using System.Threading.Tasks;
    8. namespace PSN.Extensions
    9. {
    10. /// <summary>
    11. /// Utilities used throughout the project
    12. /// </summary>
    13. public static class Utilities
    14. {
    15. /// <summary>
    16. /// Setups a request for the SendRequest methods in this class.
    17. /// </summary>
    18. /// <param name="method">The HTTP method.</param>
    19. /// <param name="url">The URL of the service to be requested.</param>
    20. /// <param name="oAuthToken">The Authorization Bearer for the service if it requires authentication (optional).</param>
    21. /// <param name="data">The GET data for the service.</param>
    22. /// <param name="headers">Headers to be sent with the request to the service (optional).</param>
    23. /// <param name="cookies">Cookies to be sent in the header with the request to the service (optional).</param>
    24. /// <returns>FlurlClient object to be used to send the request.</returns>
    25. private static FlurlClient SetupRequest(HttpMethod method, string url, string oAuthToken = "", object data = null, object headers = null, object cookies = null) {
    26. if (method == HttpMethod.Get && data != null)
    27. url = url.SetQueryParams(data);
    28. FlurlClient fc = new FlurlClient(url);
    29. if (headers != null)
    30. fc = fc.WithHeaders(headers);
    31. if (cookies != null)
    32. fc = fc.WithCookies(cookies);
    33. if (!string.IsNullOrEmpty(oAuthToken))
    34. fc = fc.WithHeader("Authorization", new AuthenticationHeaderValue("Bearer", oAuthToken));
    35. return fc.AllowAnyHttpStatus();
    36. }
    37. /// <summary>
    38. /// Sends a request.
    39. /// </summary>
    40. /// <param name="method">The HttpMethod to use.</param>
    41. /// <param name="flurlClient">The FlurlClient object to use for the request.</param>
    42. /// <param name="content">HttpContent object of the data to be sent.</param>
    43. /// <returns>HttpResponseMessage object to be read.</returns>
    44. public static async Task<HttpResponseMessage> SendRequest(HttpMethod method, FlurlClient flurlClient, HttpContent content) {
    45. return await flurlClient.SendAsync(method, content);
    46. }
    47. /// <summary>
    48. /// Sends a GET request with optional arguments, headers and cookies.
    49. /// </summary>
    50. /// <param name="url">The URL of the service to be requested.</param>
    51. /// <param name="oAuthToken">The Authorization Bearer for the service if it requires authentication (optional).</param>
    52. /// <param name="data">The GET data for the service.</param>
    53. /// <param name="headers">Headers to be sent with the request to the service (optional).</param>
    54. /// <param name="cookies">Cookies to be sent in the header with the request to the service (optional).</param>
    55. /// <returns>HttpResponseMessage object to be read.</returns>
    56. public static async Task<HttpResponseMessage> SendGetRequest(string url, string oAuthToken = "", object data = null, object headers = null, object cookies = null) {
    57. FlurlClient fc = SetupRequest(HttpMethod.Get, url, oAuthToken, data, headers, cookies);
    58. return await fc.GetAsync();
    59. }
    60. /// <summary>
    61. /// Sends a normal POST request with headers and cookies (if supplied).
    62. /// </summary>
    63. /// <param name="url">The URL of the service to be requested.</param>
    64. /// <param name="data">The POST data for the service.</param>
    65. /// <param name="oAuthToken">The Authorization Bearer for the service if it requires authentication (optional).</param>
    66. /// <param name="headers">Headers to be sent with the request to the service (optional).</param>
    67. /// <param name="cookies">Cookies to be sent in the header with the request to the service (optional).</param>
    68. /// <returns>HttpResponseMessage object to be read.</returns>
    69. public static async Task<HttpResponseMessage> SendPostRequest(string url, object data, string oAuthToken = "", object headers = null, object cookies = null) {
    70. FlurlClient fc = SetupRequest(HttpMethod.Post, url, oAuthToken, data, headers, cookies);
    71. return await fc.PostUrlEncodedAsync(data);
    72. }
    73. /// <summary>
    74. /// Sends a JSON POST request with headers and cookies (if supplied).
    75. /// </summary>
    76. /// <param name="url">The URL of the service to be requested.</param>
    77. /// <param name="data">The POST data for the service.</param>
    78. /// <param name="oAuthToken">The Authorization Bearer for the service if it requires authentication (optional).</param>
    79. /// <param name="headers">Headers to be sent with the request to the service (optional).</param>
    80. /// <param name="cookies">Cookies to be sent in the header with the request to the service (optional).</param>
    81. /// <returns>HttpResponseMessage object to be read.</returns>
    82. public static async Task<HttpResponseMessage> SendJsonPostRequest(string url, object data, string oAuthToken = "", object headers = null, object cookies = null) {
    83. FlurlClient fc = SetupRequest(HttpMethod.Post, url, oAuthToken, data, headers, cookies);
    84. return await fc.PostJsonAsync(data);
    85. }
    86. /// <summary>
    87. /// Sends a DELETE request with headers and cookies (if supplied).
    88. /// </summary>
    89. /// <param name="url">The URL of the service to be requested.</param>
    90. /// <param name="oAuthToken">The Authorization Bearer for the service if it requires authentication (optional).</param>
    91. /// <param name="headers">Headers to be sent with the request to the service (optional).</param>
    92. /// <param name="cookies">Cookies to be sent in the header with the request to the service (optional).</param>
    93. /// <returns>HttpResponseMessage object to be read.</returns>
    94. public static async Task<HttpResponseMessage> SendDeleteRequest(string url, string oAuthToken = "", object headers = null, object cookies = null) {
    95. FlurlClient fc = SetupRequest(HttpMethod.Delete, url, oAuthToken, null, headers, cookies);
    96. return await fc.DeleteAsync();
    97. }
    98. /// <summary>
    99. /// Sends a JSON PUT request with headers and cookies (if supplied).
    100. /// </summary>
    101. /// <param name="url">The URL of the service to be requested.</param>
    102. /// <param name="data">The POST data for the service.</param>
    103. /// <param name="oAuthToken">The Authorization Bearer for the service if it requires authentication (optional).</param>
    104. /// <param name="headers">Headers to be sent with the request to the service (optional).</param>
    105. /// <param name="cookies">Cookies to be sent in the header with the request to the service (optional).</param>
    106. /// <returns>HttpResponseMessage object to be read.</returns>
    107. public static async Task<HttpResponseMessage> SendPutRequest(string url, object data, string oAuthToken = "", object headers = null, object cookies = null) {
    108. FlurlClient fc = SetupRequest(HttpMethod.Put, url, oAuthToken, data, headers, cookies);
    109. //This API shouldn't have a service for PUTting non-JSON data.
    110. return await fc.PutJsonAsync(data);
    111. }
    112. //TODO: maybe a SendPATCHRequest method (only if necessary).
    113. /// <summary>
    114. /// Checks if a dynamic ExpandoObject contains a key and is not null.
    115. /// </summary>
    116. /// <param name="o">The ExpandoObject to check</param>
    117. /// <param name="key">The key to check</param>
    118. /// <returns>True if key exists, false if otherwise.</returns>
    119. public static bool ContainsKey(this ExpandoObject o, string key) {
    120. return ((o != null) && ((IDictionary<string, object>)o).ContainsKey(key));
    121. }
    122. }
    123. }



    Die Komplette User.cs: (Fehler bei zeile 123)
    Spoiler anzeigen

    C#-Quellcode

    1. using Flurl.Http;
    2. using Newtonsoft.Json;
    3. using Newtonsoft.Json.Linq;
    4. using PSN.APIResponses;
    5. using PSN.Extensions;
    6. using PSN.Requests;
    7. using System;
    8. using System.Net.Http;
    9. using System.Net.Http.Headers;
    10. using System.Threading.Tasks;
    11. namespace PSN
    12. {
    13. public class User
    14. {
    15. /// <summary>
    16. /// Contains profile information for the user.
    17. /// </summary>
    18. public Profile Profile { get; protected set; }
    19. /// <summary>
    20. /// Instantiates a new User object and fetches the profile of the PSN.
    21. /// </summary>
    22. /// <param name="psn">The PSN onlineId of the user.</param>
    23. public User(string psn) {
    24. Profile = Task.Run(() => GetInfo(psn)).Result;
    25. }
    26. /// <summary>
    27. /// Instantiates a new User object using a Profile object.
    28. /// </summary>
    29. /// <param name="profile">The Profile of the PSN.</param>
    30. public User(Profile profile) {
    31. Profile = profile;
    32. }
    33. /// <summary>
    34. /// Fetches profile of a user.
    35. /// </summary>
    36. /// <param name="psn">The PSN online Id of the user.</param>
    37. /// <returns>A profile object containing the user's info</returns>
    38. private static async Task<Profile> GetInfo(string psn) {
    39. var response = await Utilities.SendGetRequest($"{APIEndpoints.USERS_URL}{psn}/profile2?fields=npId,onlineId,avatarUrls,plus,aboutMe,languagesUsed,trophySummary(@default,progress,earnedTrophies),isOfficiallyVerified,personalDetail(@default,profilePictureUrls),personalDetailSharing,personalDetailSharingRequestMessageFlag,primaryOnlineStatus,presences(@titleInfo,hasBroadcastData),friendRelation,requestMessageFlag,blocking,mutualFriendsCount,following,followerCount,friendsCount,followingUsersCount&avatarSizes=m,xl&profilePictureSizes=m,xl&languagesUsedLanguageSet=set3&psVitaTitleIcon=circled&titleIconSize=s", Auth.CurrentInstance.AccountTokens.Authorization).ReceiveString();
    40. Profile p = JsonConvert.DeserializeObject<Profile>(JObject.Parse(response).SelectToken("profile").ToString());
    41. return p;
    42. }
    43. /// <summary>
    44. /// Adds the current user as a friend. (Same as Account.AddFriend, but adds the current User object as a friend)
    45. /// </summary>
    46. /// <param name="requestMessage">The message to send with the request (optional).</param>
    47. /// <returns>True if the user was successfully added.</returns>
    48. public async Task<bool> AddFriend(string requestMessage = "") {
    49. object message = (string.IsNullOrEmpty(requestMessage)) ? new object() : new
    50. {
    51. requestMessage = requestMessage
    52. };
    53. var response = await Utilities.SendJsonPostRequest($"{APIEndpoints.USERS_URL}{Auth.CurrentInstance.Profile.onlineId}/friendList/{this.Profile.onlineId}", message, Auth.CurrentInstance.AccountTokens.Authorization).ReceiveJson();
    54. if (Utilities.ContainsKey(response, "error"))
    55. throw new Exception(response.error.message);
    56. return true;
    57. }
    58. /// <summary>
    59. /// Removes the current user from your friends list. (Same as Account.RemoveFriend, but removes the current User object from your friends list.)
    60. /// </summary>
    61. /// <returns>True if the user was successfully removed.</returns>
    62. public async Task<bool> RemoveFriend() {
    63. var response = await Utilities.SendDeleteRequest($"{APIEndpoints.USERS_URL}{Auth.CurrentInstance.Profile.onlineId}/friendList/{this.Profile.onlineId}", Auth.CurrentInstance.AccountTokens.Authorization).ReceiveJson();
    64. if (Utilities.ContainsKey(response, "error"))
    65. throw new Exception(response.error.message);
    66. return true;
    67. }
    68. /// <summary>
    69. /// Blocks the current user. (Same as Account.BlockUser, but blocks the current user object.)
    70. /// </summary>
    71. /// <returns>True if the user was blocked.</returns>
    72. public async Task<bool> Block() {
    73. //This service requires the request to be a JSON POST request... not sure why it doesn't accept GET or PUT. So I'll just pass null for the data.
    74. var response = await Utilities.SendJsonPostRequest($"{APIEndpoints.USERS_URL}{Auth.CurrentInstance.Profile.onlineId}/blockList/{this.Profile.onlineId}", null, Auth.CurrentInstance.AccountTokens.Authorization).ReceiveJson();
    75. //Since we pass null for the JSON POST data, the response likes to be null too...
    76. if (Utilities.ContainsKey(response, "error"))
    77. throw new Exception(response.error.message);
    78. return true;
    79. }
    80. /// <summary>
    81. /// Unblocks the current user. (Same as Account.UnblockUser, but unblocks the current user object.)
    82. /// </summary>
    83. /// <returns>True if the user was unblocked successfully.</returns>
    84. public async Task<bool> Unblock() {
    85. var response = await Utilities.SendDeleteRequest($"{APIEndpoints.USERS_URL}{Auth.CurrentInstance.Profile.onlineId}/blockList/{this.Profile.onlineId}", Auth.CurrentInstance.AccountTokens.Authorization).ReceiveJson();
    86. if (Utilities.ContainsKey(response, "error"))
    87. throw new Exception(response.error.message);
    88. return true;
    89. }
    90. /// <summary>
    91. /// Sends a message to the current User instance.
    92. /// </summary>
    93. /// <param name="messageContent">Message object containing the details for the message.</param>
    94. /// <returns>True if the message gets sent successfully.</returns>
    95. public async Task<bool> SendMessage(Message messageContent) {
    96. if (messageContent == null)
    97. return false;
    98. //Set the receiver of the message to the current user.
    99. messageContent.Receiver = this;
    100. if (messageContent.MessageType == MessageType.MessageText)
    101. {
    102. MessageRequest mr = new MessageRequest(messageContent.UsersToInvite, new MessageData(messageContent.MessageText, 1));
    103. var message = mr.BuildTextMessage();
    104. FlurlClient fc = new FlurlClient("https://us-gmsg.np.community.playstation.net/groupMessaging/v1/messageGroups")
    105. .WithHeader("Authorization", new AuthenticationHeaderValue("Bearer", Auth.CurrentInstance.AccountTokens.Authorization));
    106. var response = await Utilities.SendRequest(HttpMethod.Post, fc, message).ReceiveJson();
    107. if (Utilities.ContainsKey(response, "error"))
    108. throw new Exception(response.error.message);
    109. return true;
    110. }
    111. //TODO: Add other messageTypes (audio and images)
    112. throw new NotImplementedException();
    113. }
    114. /// <summary>
    115. /// Compares the current User's trophies with the current logged in account.
    116. /// </summary>
    117. /// <param name="offset"></param>
    118. /// <param name="limit"></param>
    119. /// <returns></returns>
    120. public async Task<TrophyResponses.CompareTrophiesResponse> CompareTrophies(int offset = 0, int limit = 36) {
    121. var response = await Utilities.SendGetRequest($"https://us-tpy.np.community.playstation.net/trophy/v1/trophyTitles?fields=@default&npLanguage=en&iconSize=m&platform=PS3,PSVITA,PS4&offset={offset}&limit={limit}&comparedUser={this.Profile.onlineId}", Auth.CurrentInstance.AccountTokens.Authorization).ReceiveJson<TrophyResponses.CompareTrophiesResponse>();
    122. return response;
    123. }
    124. /// <summary>
    125. /// Gets the activity of the current User.
    126. /// </summary>
    127. /// <returns>An ActivityResponse object containing a list of all the posts.</returns>
    128. public async Task<Activity.ActivityResponse> GetActivity() {
    129. var response = await Utilities.SendGetRequest($"https://activity.api.np.km.playstation.net/activity/api/v1/users/{this.Profile.onlineId}/feed/0?includeComments=true&includeTaggedItems=true&filters=PURCHASED&filters=RATED&filters=VIDEO_UPLOAD&filters=SCREENSHOT_UPLOAD&filters=PLAYED_GAME&filters=WATCHED_VIDEO&filters=TROPHY&filters=BROADCASTING&filters=LIKED&filters=PROFILE_PIC&filters=FRIENDED&filters=CONTENT_SHARE&filters=IN_GAME_POST&filters=RENTED&filters=SUBSCRIBED&filters=FIRST_PLAYED_GAME&filters=IN_APP_POST&filters=APP_WATCHED_VIDEO&filters=SHARE_PLAYED_GAME&filters=VIDEO_UPLOAD_VERIFIED&filters=SCREENSHOT_UPLOAD_VERIFIED&filters=SHARED_EVENT&filters=JOIN_EVENT&filters=TROPHY_UPLOAD&filters=FOLLOWING&filters=RESHARE", Auth.CurrentInstance.AccountTokens.Authorization).ReceiveJson<Activity.ActivityResponse>();
    130. return response;
    131. }
    132. }
    133. }



    lg
    Begeisterter BF4 Spieler :D

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Gangsterkrafter“ ()

    Gangsterkrafter schrieb:

    sind die Releases Leer.
    Das wird deswegen so sein, weil über die .gitignore DAtei im Release Ordner nur Sourcecode Dateien ge-git-tet werden. Executables werden halt ausgeschlossen, da die manchmal/meistens Probleme mit dem AV machen.

    Ich zum Beleistift finde es sogar gut, wenn man das Projekt selber kompillieren muss, da man dann davon ausgehen kann, dass man auch nur das am PC hat, was da auch in den Sourcen steht und nicht irgendein Mist.
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell

    VaporiZed schrieb:

    gibt wohl etwas vom Typ IFlurlClient wieder
    Hast Recht, WithHeaders und Co geben alle ein IFlurlClient Interface zurück.

    VaporiZed schrieb:

    falls man der Namensgebung mit dem führenden "I" glauben darf
    Du darfst davona ausgehen ;D

    Lg Radinator
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell